Module: DateTime::ParseTimeStampExtension

Included in:
DateTime, AllLeap, Fixed360Day, NoLeap
Defined in:
lib/timesteps/parse_timestamp.rb

Instance Method Summary collapse

Instance Method Details

#parse_timestamp(spec, start = Date::ITALY, bc: false) ⇒ DateTimeFixedDPY

Parses the given datetime expression and creates an instance. ‘DateTime._parse()` is called internally.

Parameters:

  • spec (String)
  • bc (Hash) (defaults to: false)

    a customizable set of options

Options Hash (bc:):

  • (Boolean)

Returns:

  • (DateTimeFixedDPY)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/timesteps/parse_timestamp.rb', line 13

def parse_timestamp (spec, start=Date::ITALY, bc: false)
  hash = DateTime._parse(spec)
  year, month, day, hour, minute, second, sec_fraction, offset = 
         hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset)
  if bc and year < 0
    year = year + 1
  end
  hour   ||= 0
  minute ||= 0
  second ||= 0.0
  sec_fraction ||= 0.0
  offset ||= 0
  if hour == 24 && minute == 0 && second == 0.0
    self.new(year, month, day, 23, minute, second + sec_fraction, offset.quo(86400), start) + 1.quo(24)
  else
    self.new(year, month, day, hour, minute, second + sec_fraction, offset.quo(86400), start)
  end
end