Class: Biz::DayTime

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/biz/day_time.rb

Defined Under Namespace

Modules: Timestamp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(day_second) ⇒ DayTime

Returns a new instance of DayTime.



66
67
68
# File 'lib/biz/day_time.rb', line 66

def initialize(day_second)
  @day_second = Integer(day_second)
end

Instance Attribute Details

#day_secondObject (readonly)

Returns the value of attribute day_second.



57
58
59
# File 'lib/biz/day_time.rb', line 57

def day_second
  @day_second
end

Class Method Details

.endnightObject



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

def endnight
  ENDNIGHT
end

.from_hour(hour) ⇒ Object



25
26
27
# File 'lib/biz/day_time.rb', line 25

def from_hour(hour)
  new(hour * Time::HOUR)
end

.from_minute(minute) ⇒ Object



21
22
23
# File 'lib/biz/day_time.rb', line 21

def from_minute(minute)
  new(minute * Time::MINUTE)
end

.from_time(time) ⇒ Object



17
18
19
# File 'lib/biz/day_time.rb', line 17

def from_time(time)
  new(time.hour * Time::HOUR + time.min * Time::MINUTE + time.sec)
end

.from_timestamp(timestamp) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/biz/day_time.rb', line 29

def from_timestamp(timestamp)
  timestamp.match(Timestamp::PATTERN) { |match|
    new(
      match[:hour].to_i * Time::HOUR +
        match[:minute].to_i * Time::MINUTE +
        match[:second].to_i
    )
  }
end

.midnightObject Also known as: am



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

def midnight
  MIDNIGHT
end

.noonObject Also known as: pm



45
46
47
# File 'lib/biz/day_time.rb', line 45

def noon
  NOON
end

Instance Method Details

#coerce(other) ⇒ Object



90
91
92
# File 'lib/biz/day_time.rb', line 90

def coerce(other)
  [self.class.new(other), self]
end

#day_minuteObject



82
83
84
# File 'lib/biz/day_time.rb', line 82

def day_minute
  hour * Time::MINUTES_IN_HOUR + minute
end

#hourObject



70
71
72
# File 'lib/biz/day_time.rb', line 70

def hour
  day_second / Time::HOUR
end

#minuteObject



74
75
76
# File 'lib/biz/day_time.rb', line 74

def minute
  day_second % Time::HOUR / Time::MINUTE
end

#secondObject



78
79
80
# File 'lib/biz/day_time.rb', line 78

def second
  day_second % Time::MINUTE
end

#timestampObject



86
87
88
# File 'lib/biz/day_time.rb', line 86

def timestamp
  format(Timestamp::FORMAT, hour, minute)
end