class Mhc::PropertyValue::Time

Public Class Methods

parse(string, default = nil) click to toggle source
# File lib/mhc/property_value/time.rb, line 20
def self.parse(string, default = nil)
  new.parse(string, default)
end

Public Instance Methods

<=>(o) click to toggle source
# File lib/mhc/property_value/time.rb, line 28
def <=>(o)
  return @sec <=> o.to_i
end
days() click to toggle source
# File lib/mhc/property_value/time.rb, line 24
def days;    (@sec        ) / 86400 ;end
hour() click to toggle source
# File lib/mhc/property_value/time.rb, line 25
def hour;    (@sec % 86400) / 3600  ;end
minute() click to toggle source
# File lib/mhc/property_value/time.rb, line 26
def minute;  (@sec % 3600)  / 60    ;end
parse(string, default = nil) click to toggle source
# File lib/mhc/property_value/time.rb, line 10
def parse(string, default = nil)
  # default is dummy for matching interface
  if /^(\d+):(\d+)$/ =~ string
    @sec = ($1.to_i) * 3600 + ($2.to_i) * 60
  else
    raise ParseError, "invalid time format \"#{string}\""
  end
  return self
end
to_a() click to toggle source
# File lib/mhc/property_value/time.rb, line 42
def to_a
  return [hour, minute]
end
to_datetime(date = Mhc::PropertyValue::Date.new(1970, 1, 2)) click to toggle source
# File lib/mhc/property_value/time.rb, line 46
def to_datetime(date = Mhc::PropertyValue::Date.new(1970, 1, 2))
  date = date + days
  time = ::DateTime.new(date.year, date.month, date.day, hour, minute, 0, DateTime.now.zone) # make local DateTime
end
to_i() click to toggle source
# File lib/mhc/property_value/time.rb, line 38
def to_i
  return @sec
end
to_mhc_string() click to toggle source
# File lib/mhc/property_value/time.rb, line 32
def to_mhc_string
  return format("%02d:%02d", hour, minute)
end
Also aliased as: to_s
to_s()
Alias for: to_mhc_string