Module: TimeWin::Util

Included in:
TimeWin
Defined in:
lib/time_win/util.rb

Instance Method Summary collapse

Instance Method Details

#last_monthObject



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_weekObject



49
50
51
# File 'lib/time_win/util.rb', line 49

def last_week
  this_week.shift -1.weeks
end

#next_monthObject



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_hourObject



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_monthObject



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_weekObject



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_yearObject



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

#todayObject



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

#tomorrowObject



57
58
59
# File 'lib/time_win/util.rb', line 57

def tomorrow
  today.shift 1.days
end

#yesterdayObject



53
54
55
# File 'lib/time_win/util.rb', line 53

def yesterday
  today.shift -1.days
end