class Surveymonkey::DateString
Constants
- TimeFormat
but for stringification we have to use strftime format
- TimelinessFormat
and have a specific format
Attributes
raw[R]
time[R]
Public Class Methods
new(datestring, args = {})
click to toggle source
# File lib/surveymonkey/datestring.rb, line 27 def initialize(datestring, args = {}) begin $log.debug(sprintf("%s: parsing '%s'", __method__, datestring)) @raw = datestring timeliness_args = { :format => TimelinessFormat } # merge additional args if provided begin timeliness_args.merge(args) rescue TypeError => e $log.error(sprintf("%s: '%s' (%s) is not a valid arguments hash", __method__, args.inspect, args.class)) end parsed = Timeliness.parse(datestring, timeliness_args) if parsed.nil? # add a time component and try again $log.info(sprintf("%s: '%s' cannot be parsed as a datetime, adding a time component", __method__, datestring)) datestring.concat(' 00:00:00') parsed = Timeliness.parse(datestring, timeliness_args) end if parsed.nil? raise StandardError, sprintf("'%s' is not a valid DateString", datestring) else @time = parsed end rescue StandardError => e $log.error(sprintf("%s: unable to parse '%s' as DateString", __method__, datestring)) raise e end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/surveymonkey/datestring.rb, line 23 def <=>(other) self.time.<=>(other) end
to_s()
click to toggle source
# File lib/surveymonkey/datestring.rb, line 19 def to_s self.time.strftime(TimeFormat) end