class Biz::DayTime

Constants

ENDNIGHT
MIDNIGHT
VALID_SECONDS

Attributes

day_second[R]

Public Class Methods

endnight() click to toggle source
# File lib/biz/day_time.rb, line 48
def endnight
  ENDNIGHT
end
from_hour(hour) click to toggle source
# File lib/biz/day_time.rb, line 30
def from_hour(hour)
  new(hour * Time.hour_seconds)
end
from_minute(minute) click to toggle source
# File lib/biz/day_time.rb, line 26
def from_minute(minute)
  new(minute * Time.minute_seconds)
end
from_time(time) click to toggle source
# File lib/biz/day_time.rb, line 18
def from_time(time)
  new(
    time.hour * Time.hour_seconds +
      time.min * Time.minute_seconds +
      time.sec
  )
end
from_timestamp(timestamp) click to toggle source
# File lib/biz/day_time.rb, line 34
def from_timestamp(timestamp)
  timestamp.match(Timestamp::PATTERN) { |match|
    new(
      match[:hour].to_i * Time.hour_seconds +
        match[:minute].to_i * Time.minute_seconds +
        match[:second].to_i
    )
  }
end
midnight() click to toggle source
# File lib/biz/day_time.rb, line 44
def midnight
  MIDNIGHT
end
new(day_second) click to toggle source
# File lib/biz/day_time.rb, line 54
def initialize(day_second)
  @day_second = Integer(day_second)

  fail ArgumentError, 'second not within a day' unless valid_second?
end

Public Instance Methods

day_minute() click to toggle source
# File lib/biz/day_time.rb, line 74
def day_minute
  hour * Time.hour_minutes + minute
end
for_dst() click to toggle source
# File lib/biz/day_time.rb, line 78
def for_dst
  self.class.new((day_second + Time.hour_seconds) % Time.day_seconds)
end
hour() click to toggle source
# File lib/biz/day_time.rb, line 62
def hour
  day_second / Time.hour_seconds
end
minute() click to toggle source
# File lib/biz/day_time.rb, line 66
def minute
  day_second % Time.hour_seconds / Time.minute_seconds
end
second() click to toggle source
# File lib/biz/day_time.rb, line 70
def second
  day_second % Time.minute_seconds
end
timestamp() click to toggle source
# File lib/biz/day_time.rb, line 82
def timestamp
  format(Timestamp::FORMAT, hour, minute)
end

Private Instance Methods

<=>(other) click to toggle source
# File lib/biz/day_time.rb, line 92
def <=>(other)
  return unless other.is_a?(self.class)

  day_second <=> other.day_second
end
valid_second?() click to toggle source
# File lib/biz/day_time.rb, line 88
def valid_second?
  VALID_SECONDS.cover?(day_second)
end