class Transit::WriteHandlers::TimeHandler
TimeHandler
, DateTimeHandler
, and DateHandler
all have different implementations of string_rep. Here is the rationale:
For all three, want to write out the same format e.g. 2014-04-18T18:51:29.478Z, and we want the milliseconds to truncate rather than round, eg 29.4786 seconds should be 29.478, not 29.479.
-
“sss is the number of complete milliseconds since the start of the
second as three decimal digits."
Some data points (see benchmarks/encoding_time.rb)
-
Time and DateTime each offer iso8601 methods, but strftime is faster.
-
DateTime's strftime (and iso8601) round millis
-
Time's strftime (and iso8601) truncate millis
-
we don't care about truncate v round for dates (which have 000 ms)
-
date.to_datetime.strftime(…) is considerably faster than date.to_time.strftime(…)
Public Instance Methods
rep(t)
click to toggle source
# File lib/transit/write_handlers.rb, line 292 def rep(t) DateTimeUtil.to_millis(t) end
string_rep(t)
click to toggle source
# File lib/transit/write_handlers.rb, line 293 def string_rep(t) rep(t).to_s end
tag(_)
click to toggle source
# File lib/transit/write_handlers.rb, line 291 def tag(_) "m" end
verbose_handler()
click to toggle source
# File lib/transit/write_handlers.rb, line 294 def verbose_handler() VerboseTimeHandler.new end