Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/rubee/support/time.rb
Class Method Summary collapse
- .beginning_of_today ⇒ Object
- .end_of_today ⇒ Object
- .start_of_today ⇒ Object
- .today ⇒ Object
- .tomorrow ⇒ Object
- .yesterday ⇒ Object
Instance Method Summary collapse
- #add_days(days) ⇒ Object
- #all_day ⇒ Object
- #at(hr, mn, sc) ⇒ Object
- #beginning_of_day ⇒ Object
- #closest_future_working_day ⇒ Object
- #days_seconds ⇒ Object
- #end_of_day ⇒ Object
- #subtract_days(days) ⇒ Object
- #with_current_time ⇒ Object
Class Method Details
.beginning_of_today ⇒ Object
53 54 55 |
# File 'lib/rubee/support/time.rb', line 53 def beginning_of_today new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 0) end |
.end_of_today ⇒ Object
57 58 59 |
# File 'lib/rubee/support/time.rb', line 57 def end_of_today new(Time.now.year, Time.now.month, Time.now.day, 23, 59, 59) end |
.start_of_today ⇒ Object
61 62 63 |
# File 'lib/rubee/support/time.rb', line 61 def start_of_today new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 0) end |
.today ⇒ Object
41 42 43 |
# File 'lib/rubee/support/time.rb', line 41 def today Time.now end |
.tomorrow ⇒ Object
45 46 47 |
# File 'lib/rubee/support/time.rb', line 45 def tomorrow today.add_days(1) end |
.yesterday ⇒ Object
49 50 51 |
# File 'lib/rubee/support/time.rb', line 49 def yesterday today.subtract_days(1) end |
Instance Method Details
#add_days(days) ⇒ Object
22 23 24 |
# File 'lib/rubee/support/time.rb', line 22 def add_days(days) self + days * 86_400 end |
#all_day ⇒ Object
18 19 20 |
# File 'lib/rubee/support/time.rb', line 18 def all_day beginning_of_day..end_of_day end |
#at(hr, mn, sc) ⇒ Object
14 15 16 |
# File 'lib/rubee/support/time.rb', line 14 def at(hr, mn, sc) Time.new(year, month, day, hr, mn, sc) end |
#beginning_of_day ⇒ Object
6 7 8 |
# File 'lib/rubee/support/time.rb', line 6 def beginning_of_day Time.new(year, month, day, 0, 0, 0) end |
#closest_future_working_day ⇒ Object
30 31 32 33 34 |
# File 'lib/rubee/support/time.rb', line 30 def closest_future_working_day target_day = self target_day = target_day.add_days(1) while target_day.wday == 6 || target_day.wday == 0 target_day end |
#days_seconds ⇒ Object
2 3 4 |
# File 'lib/rubee/support/time.rb', line 2 def days_seconds hour * 3600 + min * 60 + sec end |
#end_of_day ⇒ Object
10 11 12 |
# File 'lib/rubee/support/time.rb', line 10 def end_of_day Time.new(year, month, day, 23, 59, 59) end |
#subtract_days(days) ⇒ Object
26 27 28 |
# File 'lib/rubee/support/time.rb', line 26 def subtract_days(days) self - days * 86_400 end |