diff options
| author | Alban Peignier | 2018-04-03 14:58:47 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2018-04-03 14:58:47 +0200 | 
| commit | b7d4892741f5b98a45a6a7660e6f174106b02dd7 (patch) | |
| tree | e8c88207833b5bffad630b34c9abab25a64c9c57 /lib | |
| parent | ee0b5b354445f23940e6a17a8d94f3d65a0b8f7d (diff) | |
| download | chouette-core-b7d4892741f5b98a45a6a7660e6f174106b02dd7.tar.bz2 | |
Add GTFS::Time and use it to compute day offset for VehicleJourneys. Refs #6368
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 | 
