Class: Biz::Time

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time_zone) ⇒ Time

Returns a new instance of Time.



71
72
73
# File 'lib/biz/time.rb', line 71

def initialize(time_zone)
  @time_zone = time_zone
end

Class Method Details

.big_bangObject



63
64
65
# File 'lib/biz/time.rb', line 63

def self.big_bang
  BIG_BANG
end

.day_hoursObject



39
40
41
# File 'lib/biz/time.rb', line 39

def self.day_hours
  DAY_HOURS
end

.day_minutesObject



55
56
57
# File 'lib/biz/time.rb', line 55

def self.day_minutes
  DAY_MINUTES
end

.day_secondsObject



51
52
53
# File 'lib/biz/time.rb', line 51

def self.day_seconds
  DAY_SECONDS
end

.heat_deathObject



67
68
69
# File 'lib/biz/time.rb', line 67

def self.heat_death
  HEAT_DEATH
end

.hour_minutesObject



35
36
37
# File 'lib/biz/time.rb', line 35

def self.hour_minutes
  HOUR_MINUTES
end

.hour_secondsObject



47
48
49
# File 'lib/biz/time.rb', line 47

def self.hour_seconds
  HOUR_SECONDS
end

.minute_secondsObject



31
32
33
# File 'lib/biz/time.rb', line 31

def self.minute_seconds
  MINUTE_SECONDS
end

.week_daysObject



43
44
45
# File 'lib/biz/time.rb', line 43

def self.week_days
  WEEK_DAYS
end

.week_minutesObject



59
60
61
# File 'lib/biz/time.rb', line 59

def self.week_minutes
  WEEK_MINUTES
end

Instance Method Details

#during_week(week, week_time) ⇒ Object



95
96
97
# File 'lib/biz/time.rb', line 95

def during_week(week, week_time)
  on_date(week.start_date + week_time.wday, week_time.day_time)
end

#local(time) ⇒ Object



75
76
77
# File 'lib/biz/time.rb', line 75

def local(time)
  time_zone.utc_to_local(time.utc)
end

#on_date(date, day_time) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/biz/time.rb', line 79

def on_date(date, day_time)
  time_zone.local_to_utc(
    ::Time.new(
      date.year,
      date.month,
      date.mday,
      day_time.hour,
      day_time.minute,
      day_time.second
    ),
    true
  )
rescue TZInfo::PeriodNotFound
  on_date(Date.for_dst(date, day_time), day_time.for_dst)
end