class EorzeaTime

Constants

DAY
HOUR
RATIO
VERSION

Public Class Methods

from_time(t) click to toggle source
# File lib/eorzea_time.rb, line 11
def self.from_time(t)
  new(t.to_f * RATIO) # ET 1440m (24h) in LT is 70m
end
new(i) click to toggle source
# File lib/eorzea_time.rb, line 15
def initialize(i)
  @epoch = i % 86400
  @time = Time.at(@epoch).utc
end
now() click to toggle source
# File lib/eorzea_time.rb, line 7
def self.now
  from_time Time.now
end

Public Instance Methods

+(o) click to toggle source
# File lib/eorzea_time.rb, line 24
def +(o)
  self.class.new @epoch + o
end
-(o) click to toggle source
# File lib/eorzea_time.rb, line 28
def -(o)
  self.class.new @epoch - o
end
hour() click to toggle source
# File lib/eorzea_time.rb, line 32
def hour
  @time.hour
end
inspect() click to toggle source
# File lib/eorzea_time.rb, line 48
def inspect
  "#<EorzeaTime #{to_s}>"
end
last_occurrence(time: Time.now, count: 1) click to toggle source
# File lib/eorzea_time.rb, line 71
def last_occurrence(time: Time.now, count: 1)
  o = occurrence(time)
  if o < time
    o - ((count - 1) * DAY)
  else
    o - (count * DAY)
  end
end
min() click to toggle source
# File lib/eorzea_time.rb, line 36
def min
  @time.min
end
next_occurrence(time: Time.now, count: 1) click to toggle source
# File lib/eorzea_time.rb, line 80
def next_occurrence(time: Time.now, count: 1)
  o = occurrence(time)
  if o > time
    o + ((count - 1) * DAY)
  else
    o + (count * DAY)
  end
end
occurrence(time = Time.now) click to toggle source
# File lib/eorzea_time.rb, line 65
def occurrence(time = Time.now)
  last_midnight = time.to_i / DAY * DAY
  seconds_passed_in_local = (@epoch / RATIO).to_i
  Time.at(last_midnight + seconds_passed_in_local).utc
end
sec() click to toggle source
# File lib/eorzea_time.rb, line 40
def sec
  @time.sec
end
to_h() click to toggle source
# File lib/eorzea_time.rb, line 56
def to_h
  {
    i: @epoch,
    hour: hour,
    min: min,
    sec: sec,
  }
end
to_i() click to toggle source
# File lib/eorzea_time.rb, line 20
def to_i
  @epoch
end
to_s() click to toggle source
# File lib/eorzea_time.rb, line 52
def to_s
  "%02d:%02d:%02d" % [hour, min, sec]
end
usec() click to toggle source
# File lib/eorzea_time.rb, line 44
def usec
  @time.usec
end