Module: AggtiveRecord::Time
- Defined in:
- lib/aggtive_record/time.rb
Constant Summary collapse
- UNIFORM_PERIODS =
A week is always 7 * 24 * 60 * 60, for instance
[:week, :day, :hour, :minute, :second]
- NON_UNIFORM_PERIODS =
e.g. A year may have 365 days or 366
[:year, :month]
- PERIODS =
NON_UNIFORM_PERIODS + UNIFORM_PERIODS
- OTHER_PERIODS =
[:day_of_week, :hour_of_day]
- SECONDS_PER_DAY =
60 * 60 * 24
Class Method Summary collapse
- .periods ⇒ Object
-
.to_seconds(str) ⇒ Object
probably reinventing the wheel here…
Class Method Details
.periods ⇒ Object
17 18 19 |
# File 'lib/aggtive_record/time.rb', line 17 def self.periods PERIODS + OTHER_PERIODS end |
.to_seconds(str) ⇒ Object
probably reinventing the wheel here…
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aggtive_record/time.rb', line 24 def self.to_seconds(str) num, period = str.to_s.match(/^(\d*)_?(\w+?)s?$/)[1..2] num = num.to_i > 0 ? num.to_i : 1 # ugh secs = case period.to_sym when :year SECONDS_PER_DAY * 365 when :month SECONDS_PER_DAY * 30 when :week SECONDS_PER_DAY * 7 when :day SECONDS_PER_DAY when :hour 60 * 60 when :minute 60 when :second 1 end num * secs end |