LoginSignup
11
8

More than 5 years have passed since last update.

Googleカレンダーから祝日を取得する「google_holiday_calendar」

Last updated at Posted at 2016-12-22

祝日ということでGoogleの祝日カレンダーにアクセスするためのgemです

準備

API実行のためのトークンが必要なので下記を参考に取得

Google Calendar API を使って祝日を取る PHP編 - Qiita

gem install google_holiday_calendar

使い方

require "google_holiday_calendar"

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

# holidaysで任意の期間の祝日を取得
japan_calendar.holidays(start_date: "2017-01-01", end_date: "2017-03-01", limit: 5)
#=> {Sun, 01 Jan 2017=>"元日", Mon, 02 Jan 2017=>"元日 振替休日", Mon, 09 Jan 2017=>"成人の日", Sat, 11 Feb 2017=>"建国記念の日"}

# holiday?で祝日かどうか判定
japan_calendar.holiday?("2017-01-01")
#=> true
japan_calendar.holiday?("2017-02-01")
#=> false

仕様

  • Google Calendarの仕様上、古すぎる日付やあまりにも未来の日付は取得できません
  • APIのトークン取得が面倒な場合は https://github.com/holiday-jp/holiday_jp-ruby を使うのが一番お手軽だと思います :sweat_smile:
11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8