Module: ActiveObject::Date

Defined in:
lib/active_object/date.rb

Instance Method Summary collapse

Instance Method Details

#count_centuries_since(time) ⇒ Object Also known as: count_centuries_until


98
99
100
# File 'lib/active_object/date.rb', line 98

def count_centuries_since(time)
  count_seconds_since(time) / CENTURY
end

#count_days_since(time) ⇒ Object Also known as: count_days_until


104
105
106
# File 'lib/active_object/date.rb', line 104

def count_days_since(time)
  count_seconds_since(time) / DAY
end

#count_decades_since(time) ⇒ Object Also known as: count_decades_until


110
111
112
# File 'lib/active_object/date.rb', line 110

def count_decades_since(time)
  count_seconds_since(time) / DECADE
end

#count_hours_since(time) ⇒ Object Also known as: count_hours_until


116
117
118
# File 'lib/active_object/date.rb', line 116

def count_hours_since(time)
  count_seconds_since(time) / HOUR
end

#count_milleniums_since(time) ⇒ Object Also known as: count_milleniums_until


122
123
124
# File 'lib/active_object/date.rb', line 122

def count_milleniums_since(time)
  count_seconds_since(time) / MILLENNIUM
end

#count_minutes_since(time) ⇒ Object Also known as: count_minutes_until


128
129
130
# File 'lib/active_object/date.rb', line 128

def count_minutes_since(time)
  count_seconds_since(time) / MINUTE
end

#count_seconds_since(time) ⇒ Object Also known as: count_seconds_until


134
135
136
# File 'lib/active_object/date.rb', line 134

def count_seconds_since(time)
  (to_time.to_f - time.to_time.to_f).abs
end

#count_weeks_since(time) ⇒ Object Also known as: count_weeks_until


140
141
142
# File 'lib/active_object/date.rb', line 140

def count_weeks_since(time)
  count_seconds_since(time) / WEEK
end

#count_years_since(time) ⇒ Object Also known as: count_years_until


146
147
148
# File 'lib/active_object/date.rb', line 146

def count_years_since(time)
  count_seconds_since(time) / YEAR
end

#format(string) ⇒ Object


152
153
154
155
156
157
158
# File 'lib/active_object/date.rb', line 152

def format(string)
  delimiters = string.scan(/\W+/)
  formatters = string.scan(/[a-z0-9_]+/i)
  string = formatters.map { |unit| "%#{STRING_UNITS.fetch(unit.to_sym)}#{delimiters.shift}" }

  strftime(string.join)
end

#to_format(key = :datetime_iso) ⇒ Object Also known as: stamp


160
161
162
# File 'lib/active_object/date.rb', line 160

def to_format(key = :datetime_iso)
  strftime(KEY_UNITS.fetch(key.to_sym))
end