diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gtfs/time.rb | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/lib/gtfs/time.rb b/lib/gtfs/time.rb new file mode 100644 index 000000000..49546532a --- /dev/null +++ b/lib/gtfs/time.rb @@ -0,0 +1,28 @@ +module GTFS +  class Time +    attr_reader :hours, :minutes, :seconds +    def initialize(hours, minutes, seconds) +      @hours, @minutes, @seconds = hours, minutes, seconds +    end + +    def real_hours +      hours.modulo(24) +    end + +    def time +      @time ||= ::Time.new(2000, 1, 1, real_hours, minutes, seconds, "+00:00") +    end + +    def day_offset +      hours / 24 +    end + +    FORMAT = /(\d{1,2}):(\d{2}):(\d{2})/ + +    def self.parse(definition) +      if definition.to_s =~ FORMAT +        new *[$1, $2, $3].map(&:to_i) +      end +    end +  end +end | 
