aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlban Peignier2018-04-03 14:58:47 +0200
committerAlban Peignier2018-04-03 14:58:47 +0200
commitb7d4892741f5b98a45a6a7660e6f174106b02dd7 (patch)
treee8c88207833b5bffad630b34c9abab25a64c9c57 /lib
parentee0b5b354445f23940e6a17a8d94f3d65a0b8f7d (diff)
downloadchouette-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.rb28
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