Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/support/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.beginning_of_todayObject



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_todayObject



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_todayObject



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

.todayObject



41
42
43
# File 'lib/rubee/support/time.rb', line 41

def today
  Time.now
end

.tomorrowObject



45
46
47
# File 'lib/rubee/support/time.rb', line 45

def tomorrow
  today.add_days(1)
end

.yesterdayObject



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_dayObject



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_dayObject



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_dayObject



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_secondsObject



2
3
4
# File 'lib/rubee/support/time.rb', line 2

def days_seconds
  hour * 3600 + min * 60 + sec
end

#end_of_dayObject



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

#with_current_timeObject



36
37
38
# File 'lib/rubee/support/time.rb', line 36

def with_current_time
  at(Time.now.hour, Time.now.min, Time.now.sec)
end