aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuc Donnet2018-04-10 17:30:55 +0200
committerGitHub2018-04-10 17:30:55 +0200
commit537a5078657ead0b89aa5220c05dfbc01ae94dca (patch)
tree54072303cdbab71e6005e7fc5c2af6db6a4f9d0b /lib
parentdad504f5794a36be8dac97a257cdecd87704763b (diff)
parent22e7844c1d2392e2a651a33bf83c32664a879619 (diff)
downloadchouette-core-537a5078657ead0b89aa5220c05dfbc01ae94dca.tar.bz2
Merge pull request #438 from af83/6368-gtfs-import
GTFS import (first step)
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