lib/active_object/time.rb in active_object-3.0.0 vs lib/active_object/time.rb in active_object-3.1.0
- old
+ new
@@ -1,7 +1,16 @@
module ActiveObject::Time
+ MINUTE = 60.0
+ HOUR = MINUTE * 60.0
+ DAY = HOUR * 24.0
+ WEEK = DAY * 7.0
+ YEAR = DAY * 365.25
+ DECADE = YEAR * 10.0
+ CENTURY = DECADE * 10.0
+ MILLENNIUM = CENTURY * 10.0
+
KEY_UNITS = {
month: "%m", month_padded: "%m", month_unpadded: "%-m", month_blank: "%_m",
month_name: "%B", month_name_abbr: "%b", month_year: "%m %Y",
month_padded_year: "%m %Y", month_unpadded_year: "%-m %Y",
month_blank_year: "%_m %Y", month_name_year: "%B %Y",
@@ -42,9 +51,64 @@
hour_imperical_blank: "l", ampm: "P", meridian: "P", AMPM: "p",
MERIDIAN: "p", n: "M", minute: "M", s: "S", second: "S", z: "z",
time_zone: "z", zz: ":z", time_zone_offset: ":z", zzz: "::z",
time_zone_offset_full: "::z", zzzz: "Z", time_zone_name: "Z"
}
+
+ def count_centuries_since(time)
+ count_seconds_since(time) / CENTURY
+ end
+
+ alias_method :count_centuries_until, :count_centuries_since
+
+ def count_days_since(time)
+ count_seconds_since(time) / DAY
+ end
+
+ alias_method :count_days_until, :count_days_since
+
+ def count_decades_since(time)
+ count_seconds_since(time) / DECADE
+ end
+
+ alias_method :count_decades_until, :count_decades_since
+
+ def count_hours_since(time)
+ count_seconds_since(time) / HOUR
+ end
+
+ alias_method :count_hours_until, :count_hours_since
+
+ def count_milleniums_since(time)
+ count_seconds_since(time) / MILLENNIUM
+ end
+
+ alias_method :count_milleniums_until, :count_milleniums_since
+
+ def count_minutes_since(time)
+ count_seconds_since(time) / MINUTE
+ end
+
+ alias_method :count_minutes_until, :count_minutes_since
+
+ def count_seconds_since(time)
+ time = time.to_time if time.respond_to?(:to_time)
+ (to_f - time.to_f).abs
+ end
+
+ alias_method :count_seconds_until, :count_seconds_since
+
+ def count_weeks_since(time)
+ count_seconds_since(time) / WEEK
+ end
+
+ alias_method :count_weeks_until, :count_weeks_since
+
+ def count_years_since(time)
+ count_seconds_since(time) / YEAR
+ end
+
+ alias_method :count_years_until, :count_years_since
def format(string)
delimiters = string.scan(/\W+/)
formatters = string.scan(/[a-z0-9_]+/i)