Module: Mushy::DateParts

Defined in:
lib/mushy/date_parts.rb

Class Method Summary collapse

Class Method Details

.parse(now) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mushy/date_parts.rb', line 5

def self.parse now
  {
    year: nil,
    month: nil,
    day: nil,
    hour: nil,
    minute: :min,
    second: :sec,
    nanosecond: :nsec,
    utc_offset: nil,
    weekday: :wday,
    day_of_month: :mday,
    day_of_year: :yday,
    string: :to_s,
    epoch_integer: :to_i,
    epoch_float: :to_f,
  }.reduce({}) do |t, i|
    method = i[1] || i[0]
    t[i[0]] = now.send method
    t
  end.tap do |hash|
    hash[:seconds_ago] = Time.now - now
  end
end