Module: ThreeScale::Backend::Period::Boundary::Methods
- Included in:
- ThreeScale::Backend::Period::Boundary
- Defined in:
- lib/3scale/backend/period/boundary.rb
Instance Method Summary collapse
- #day_finish(ts) ⇒ Object
- #day_start(ts) ⇒ Object
- #end_of(period, ts) ⇒ Object
- #eternity_finish(_ts) ⇒ Object
- #eternity_start(_ts) ⇒ Object
- #hour_finish(ts) ⇒ Object
- #hour_start(ts) ⇒ Object
- #minute_finish(ts) ⇒ Object
- #minute_start(ts) ⇒ Object
- #month_finish(ts) ⇒ Object
- #month_start(ts) ⇒ Object
- #second_finish(ts) ⇒ Object
- #second_start(ts) ⇒ Object
- #start_of(period, ts) ⇒ Object
- #week_finish(ts) ⇒ Object
- #week_start(ts) ⇒ Object
- #year_finish(ts) ⇒ Object
- #year_start(ts) ⇒ Object
Instance Method Details
#day_finish(ts) ⇒ Object
47 48 49 |
# File 'lib/3scale/backend/period/boundary.rb', line 47 def day_finish(ts) day_start(ts) + 86400 end |
#day_start(ts) ⇒ Object
43 44 45 |
# File 'lib/3scale/backend/period/boundary.rb', line 43 def day_start(ts) Time.utc ts.year, ts.month, ts.day end |
#end_of(period, ts) ⇒ Object
15 16 17 |
# File 'lib/3scale/backend/period/boundary.rb', line 15 def end_of(period, ts) send(:"#{period}_finish", ts) end |
#eternity_finish(_ts) ⇒ Object
92 93 94 |
# File 'lib/3scale/backend/period/boundary.rb', line 92 def eternity_finish(_ts) ETERNITY_FINISH end |
#eternity_start(_ts) ⇒ Object
88 89 90 |
# File 'lib/3scale/backend/period/boundary.rb', line 88 def eternity_start(_ts) ETERNITY_START end |
#hour_finish(ts) ⇒ Object
39 40 41 |
# File 'lib/3scale/backend/period/boundary.rb', line 39 def hour_finish(ts) hour_start(ts) + 3600 end |
#hour_start(ts) ⇒ Object
35 36 37 |
# File 'lib/3scale/backend/period/boundary.rb', line 35 def hour_start(ts) Time.utc ts.year, ts.month, ts.day, ts.hour end |
#minute_finish(ts) ⇒ Object
31 32 33 |
# File 'lib/3scale/backend/period/boundary.rb', line 31 def minute_finish(ts) minute_start(ts) + 60 end |
#minute_start(ts) ⇒ Object
27 28 29 |
# File 'lib/3scale/backend/period/boundary.rb', line 27 def minute_start(ts) Time.utc ts.year, ts.month, ts.day, ts.hour, ts.min end |
#month_finish(ts) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/3scale/backend/period/boundary.rb', line 69 def month_finish(ts) if ts.month == 12 year = ts.year + 1 month = 1 else year = ts.year month = ts.month + 1 end Time.utc year, month, 1 end |
#month_start(ts) ⇒ Object
65 66 67 |
# File 'lib/3scale/backend/period/boundary.rb', line 65 def month_start(ts) Time.utc ts.year, ts.month, 1 end |
#second_finish(ts) ⇒ Object
23 24 25 |
# File 'lib/3scale/backend/period/boundary.rb', line 23 def second_finish(ts) second_start(ts) + 1 end |
#second_start(ts) ⇒ Object
19 20 21 |
# File 'lib/3scale/backend/period/boundary.rb', line 19 def second_start(ts) Time.utc ts.year, ts.month, ts.day, ts.hour, ts.min, ts.sec end |
#start_of(period, ts) ⇒ Object
11 12 13 |
# File 'lib/3scale/backend/period/boundary.rb', line 11 def start_of(period, ts) send(:"#{period}_start", ts) end |
#week_finish(ts) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/3scale/backend/period/boundary.rb', line 58 def week_finish(ts) wday = ts.wday days_to_next_monday = wday != 0 ? 8 - wday : 1 dayts = ts + days_to_next_monday * 86400 Time.utc dayts.year, dayts.month, dayts.day end |
#week_start(ts) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/3scale/backend/period/boundary.rb', line 51 def week_start(ts) wday = ts.wday days_to_monday = wday != 0 ? wday - 1 : 6 dayts = ts - days_to_monday * 86400 Time.utc dayts.year, dayts.month, dayts.day end |
#year_finish(ts) ⇒ Object
84 85 86 |
# File 'lib/3scale/backend/period/boundary.rb', line 84 def year_finish(ts) Time.utc ts.year + 1, 1, 1 end |
#year_start(ts) ⇒ Object
80 81 82 |
# File 'lib/3scale/backend/period/boundary.rb', line 80 def year_start(ts) Time.utc ts.year, 1, 1 end |