module OpeningHoursConverter::Utils
Public Instance Methods
add_days_to_time(time, days)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 12 def add_days_to_time(time, days) time + days * seconds_in_day end
datetime_to_time(datetime)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 43 def datetime_to_time(datetime) Time.new(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec, datetime.zone) end
day_difference(from, to)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 16 def day_difference(from, to) to - from end
last_day_of_month(month, year)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 34 def last_day_of_month(month, year) return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] unless leap_year?(year) && month == 1 return 29 end
leap_year?(year = Time.now.year)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 30 def leap_year?(year = Time.now.year) year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) end
reindex_sunday_week_to_monday_week(wday)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 3 def reindex_sunday_week_to_monday_week(wday) (wday + 6) % 7 end
seconds_in_day()
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 26 def seconds_in_day 24 * 60 * 60 end
time_to_datetime(time)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 39 def time_to_datetime(time) DateTime.new(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.gmt_offset / 3600, 24)) end
timstring_as_minutes(time)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 7 def timstring_as_minutes(time) values = time.split(':') values[0].to_i * 60 + values[1].to_i end
week_difference(from, to)
click to toggle source
# File lib/opening_hours_converter/utils.rb, line 20 def week_difference(from, to) day_diff = to - from day_diff -= (day_diff % 7) (day_diff / 7).to_i end