Class: Transit::WriteHandlers::TimeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/transit/write_handlers.rb

Overview

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.

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(...)

Direct Known Subclasses

DateHandler, DateTimeHandler

Instance Method Summary collapse

Instance Method Details

#rep(t) ⇒ Object



292
# File 'lib/transit/write_handlers.rb', line 292

def rep(t) DateTimeUtil.to_millis(t) end

#string_rep(t) ⇒ Object



293
# File 'lib/transit/write_handlers.rb', line 293

def string_rep(t) rep(t).to_s end

#tag(_) ⇒ Object



291
# File 'lib/transit/write_handlers.rb', line 291

def tag(_) "m" end

#verbose_handlerObject



294
# File 'lib/transit/write_handlers.rb', line 294

def verbose_handler() VerboseTimeHandler.new end