Module: TimeWin::Util
- Included in:
- TimeWin
- Defined in:
- lib/time_win/util.rb
Instance Method Summary collapse
- #last_month ⇒ Object
- #last_week ⇒ Object
- #next_month ⇒ Object
- #this_hour ⇒ Object
- #this_month ⇒ Object
- #this_week ⇒ Object
- #this_year ⇒ Object
- #today ⇒ Object
- #tomorrow ⇒ Object
- #yesterday ⇒ Object
Instance Method Details
#last_month ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/time_win/util.rb', line 15 def last_month today = Time.now.to_date y = today.month == 1 ? today.year - 1 : today.year m = today.month == 1 ? 12 : today.month - 1 day_1 = Date.new(y,m,1) Window.new(day_1, day_1 + Date.days_in_month(y, m)) end |
#last_week ⇒ Object
49 50 51 |
# File 'lib/time_win/util.rb', line 49 def last_week this_week.shift -1.weeks end |
#next_month ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/time_win/util.rb', line 23 def next_month today = Time.now.to_date y = today.month == 12 ? today.year + 1 : today.year m = today.month == 12 ? 1 : today.month + 1 day_1 = Date.new(y,m,1) Window.new(day_1, day_1 + Date.days_in_month(y, m)) end |
#this_hour ⇒ Object
41 42 43 44 45 46 |
# File 'lib/time_win/util.rb', line 41 def this_hour now = Time.now now_at_0 = now.to_date begining_of_hour = now_at_0.to_time + now.hour.hours begining_of_hour.during(1.hours) end |
#this_month ⇒ Object
9 10 11 12 13 |
# File 'lib/time_win/util.rb', line 9 def this_month today = Time.now.to_date day_1 = Date.new(today.year, today.month) Window.new(day_1, day_1.to_time + Date.days_in_month(today.year, today.month).days) end |
#this_week ⇒ Object
31 32 33 34 35 |
# File 'lib/time_win/util.rb', line 31 def this_week now = Time.now monday = (now - (now.wday - 1).days).to_date.to_time monday.to_time.during(1.weeks) end |
#this_year ⇒ Object
3 4 5 6 7 |
# File 'lib/time_win/util.rb', line 3 def this_year today = Time.now.to_date day_1 = Date.new(today.year, 1, 1) Window.new(day_1, day_1 + Date.days_in_year(today.year)) end |
#today ⇒ Object
37 38 39 |
# File 'lib/time_win/util.rb', line 37 def today Time.now.to_date.to_time.to(Time.now.to_date + 1) end |
#tomorrow ⇒ Object
57 58 59 |
# File 'lib/time_win/util.rb', line 57 def tomorrow today.shift 1.days end |
#yesterday ⇒ Object
53 54 55 |
# File 'lib/time_win/util.rb', line 53 def yesterday today.shift -1.days end |