Sha256: d196079215ed88ac3ce0227f6e73785728aca02f2917830f81d2796404d39078
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true require_relative "HappyFriday/version" require 'active_support/all' require 'holiday_jp' module HappyFriday class Error < StandardError; end def happy_friday? self == self.get_next_happy_friday end def get_next_happy_friday last_of_month = self.end_of_month case last_of_month.wday when 0..4 before_friday_days = last_of_month.wday + 2 when 5..6 before_friday_days = last_of_month.wday - 5 else raise 'Unpredictable day of the week.' end last_friday = last_of_month - before_friday_days.days raise 'err' unless last_friday.wday == 5 100.times do if HolidayJp.holiday?(last_friday) last_friday -= 1 else break end end # If HappyFriday of that month has passed, get next month. if self > last_friday happy_friday = self.next_month.beginning_of_month.get_next_happy_friday else happy_friday = last_friday end happy_friday end end class Date include HappyFriday end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
HappyFriday-0.5.1 | lib/HappyFriday.rb |