くりにっき

フルスタックキュアエンジニアです

Google Calendarの祝日を取得するgemを作った

ありそうでなかったようなので勢い余ってgemを作りました*1

仕様

Googleが公開してる祝日のカレンダーをrubyでいい感じに取得できるようにしてます

ググっても公式のドキュメントが見当たらない。。。

使い方 (rubyから)

require "google_holiday_calendar"

usa_calendar = GoogleHolidayCalendar::Calendar.new(country: "usa", lang: "en")

usa_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01", limit: 5)
# => {Wed, 01 Jan 2014=>"New Year's Day", Mon, 20 Jan 2014=>"Martin Luther King Day", Fri, 14 Feb 2014=>"Valentine's Day", Mon, 17 Feb 2014=>"Presidents' Day (Washington's Birthday)"}

japan_calendar = GoogleHolidayCalendar::Calendar.new(country: "japanese", lang: "ja")

japan_calendar.holidays(start_date: "2014-01-01", end_date: "2014-03-01", limit: 5)
# => {Wed, 01 Jan 2014=>"元日", Thu, 02 Jan 2014=>"銀行休業日", Fri, 03 Jan 2014=>"銀行休業日", Mon, 13 Jan 2014=>"成人の日", Tue, 11 Feb 2014=>"建国記念の日"}
  • start_date と end_date がない場合は現在日時から1ヶ月間を取得
  • 日付は Date型かYYYY-MM-DD形式の文字列
  • 日付でソートされたHashが返ってきます

使い方 (bashから)

gem install した後に google_holiday_calendar してください。

# get holidays (today - 1 month after)
$ date +"%Y-%m-%d"
2014-02-24

$ google_holiday_calendar
2014-03-09: Daylight Saving Time starts
# get holidays (2014/01/01 - 2014/07/01)
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01
2014-01-01: New Year's Day
2014-01-20: Martin Luther King Day
2014-02-14: Valentine's Day
2014-02-17: Presidents' Day (Washington's Birthday)
2014-03-09: Daylight Saving Time starts
2014-04-13: Thomas Jefferson's Birthday
2014-04-20: Easter Sunday
2014-05-11: Mothers' Day
2014-05-26: Memorial Day
2014-06-15: Fathers' Day
# get holidays (with limit)
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --limit=3
2014-02-14: Valentine's Day
2014-02-17: Presidents' Day (Washington's Birthday)
2014-04-13: Thomas Jefferson's Birthday
# get holidays (specify country and language)
$ google_holiday_calendar --start-date=2014-01-01 --end-date=2014-07-01 --country=japanese --lang=ja
2014-01-01: 元日
2014-01-02: 銀行休業日
2014-01-03: 銀行休業日
2014-01-13: 成人の日
2014-02-11: 建国記念の日
2014-03-21: 春分の日
2014-04-29: 昭和の日
2014-05-03: 憲法記念日
2014-05-04: みどりの日
2014-05-06: みどりの日 振替休日

*1:具体的には所要時間4時間ほど