module SunbusDayLookup
SunbusDayLookup — service-day iteration and date formatting for GTFS calendars. Public: each_service_day, shift_time, format_service_date, local_date Depends: (none) Tests: test/lib/sunbus_day_lookup_test.rb
Constants
- LOCAL_OFFSET
- MAX_ADVANCE_DAYS
Public Instance Methods
Source
# File lib/sunbus/day_lookup.rb, line 14 def each_service_day(time) (0..MAX_ADVANCE_DAYS).each do |offset| yield(shift_time(time, offset), offset) end end
Source
# File lib/sunbus/day_lookup.rb, line 28 def format_service_date(date) date.strftime("%a %-d %b") end
Source
# File lib/sunbus/day_lookup.rb, line 32 def local_date(time) time.getlocal(LOCAL_OFFSET) end
Source
# File lib/sunbus/day_lookup.rb, line 20 def shift_time(base_time, day_offset) local = local_date(base_time) return base_time if day_offset.zero? date = local + (day_offset * 86_400) Time.new(date.year, date.month, date.day, 0, 0, 0, local.utc_offset) end