[Awesome Ruby Gem] Use chinese_holiday gem to initialize Chinese holidays, or add and remove your holidays

chinese_holiday

chinese_pinyin is a gem to initialize Chinese holidays, or add and remove your holidays.

Installation

You can install it as a gem:

1
$ gem install chinese_holiday https://github.com/shawndodo/chinese_holiday.git

or add it into a Gemfile (Bundler):

1
2
3
4
5
# Gemfile

# GitHub - shawndodo/chinese_holiday
# https://github.com/shawndodo/chinese_holiday
gem 'chinese_holiday', github: 'shawndodo/chinese_holiday'

Then, run bundle install.

1
$ bundle install

Usages

Run once a year to initialize the latest holiday date:

1
$ bundle exec rails run "ChineseHoliday::CalendarInit.init_calendar"

Add your holiday:

1
2
3
4
5
6
7
8
9
10
11
12
13
holiday = ChineseHoliday::ChineseCalendar.new)
holiday.current_date = Date.new("2019-01-19")
holiday.name_cn = "调休"
holiday.year = 2019
holiday.month = 1
holiday.day = 19
holiday.yday = 19
holiday.what_day = "星期六"
holiday.special_type = "工作日"
holiday.target = "工作日"
holiday.after = true

holiday.save!

Attribues of ChineseHoliday::ChineseCalendar:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# == Schema Information
#
# Table name: chinese_calendars # 中国日历
#
# id :integer not null, primary key # 中国日历
# current_date :datetime # 当前日期
# name_cn :string(255) # 当前日期中文名称
# year :integer # 年份
# month :integer # 月份
# day :integer # 日期
# yday :integer # 一年中的第几天
# what_day :string(255) # 星期几
# special_type :string(255) # 特殊类型 工作日/法定假日/公司假日/调休日
# target :string(255) # 调休所属节假日名称
# after :boolean # 调休日期所属位置,true是在节假日后,false是在节假日前
# remark :string(255) # 备注
# created_at :datetime not null
# updated_at :datetime not null
#

References

[1] GitHub - shawndodo/chinese_holiday - https://github.com/shawndodo/chinese_holiday

[3] 免费节假日 API - 提莫的神秘商店 - http://timor.tech/api/holiday/