class ScheduleChecker::Timepoint

Constants

DAYS

Attributes

normalized_ts[R]

Public Class Methods

day_str_to_i(str) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 53
def self.day_str_to_i(str)
  d = str.downcase.slice(0,3)
  rv = DAYS.find_index(d)
  raise "Illegal day string '#{str}'" unless rv
  rv
end
from_string(s,is_utc=true) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 14
def self.from_string(s,is_utc=true)
  raise "bad format '#{s}'" unless s.match(/^\w\w\w[\w]*\/\d\d:\d\d:\d\d$/)
  day_str,time_str = s.split("/")
  day = ScheduleChecker::Timepoint.day_str_to_i(day_str)
  h,m,s = time_str.split(":")
  ScheduleChecker::Timepoint.new(day,h.to_i,m.to_i,s.to_i,is_utc)
end
new(day,hour,minute,second,is_utc=true) click to toggle source

day: 0-6 for Sunday-Saturday hour: 0-24

# File lib/schedule-checker/timepoint.rb, line 7
def initialize(day,hour,minute,second,is_utc=true)
  raise "invalid day (must be 0-6, 0 is Monday)" unless (0..6).to_a.include?(day)
  @normalized_ts = is_utc ?
    Time.utc(2012,1,day+1,hour,minute,second) :
    Time.local(2012,1,day+1,hour,minute,second).getutc
end
normalize_timestamp(ts) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 42
def self.normalize_timestamp(ts)
  x = ts.getutc
  ScheduleChecker::Timepoint.new(x.wday,x.hour,x.min,x.sec).normalized_ts
end
pretty_day(n) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 48
def self.pretty_day(n)
  raise "Illegal day int '#{n}'" unless (0..6).to_a.include?(n)
  DAYS[n].capitalize
end

Public Instance Methods

gt(t) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 36
def gt(t)
  #only cares about wday and time
  x = t.is_a?(ScheduleChecker::Timepoint) ? t.normalized_ts : ScheduleChecker::Timepoint.normalize_timestamp(t)
  self.normalized_ts > x
end
lte(t) click to toggle source
# File lib/schedule-checker/timepoint.rb, line 30
def lte(t)
  #only cares about wday and time
  x = t.is_a?(ScheduleChecker::Timepoint) ? t.normalized_ts : ScheduleChecker::Timepoint.normalize_timestamp(t)
  self.normalized_ts <= x
end
normalized_ts_as_local() click to toggle source
# File lib/schedule-checker/timepoint.rb, line 22
def normalized_ts_as_local
  @normalized_ts.get_local
end
to_s() click to toggle source
# File lib/schedule-checker/timepoint.rb, line 26
def to_s
  @normalized_ts.strftime("#{wday_abbrev}/%H:%M:%S")
end

Private Instance Methods

wday_abbrev() click to toggle source
# File lib/schedule-checker/timepoint.rb, line 61
def wday_abbrev
  ScheduleChecker::Timepoint.pretty_day(@normalized_ts.wday)
end