Class: EorzeaTime

Inherits:
Object
  • Object
show all
Defined in:
lib/eorzea_time.rb,
lib/eorzea_time/version.rb

Constant Summary collapse

HOUR =

ET 1h = LT 175s

175
DAY =
HOUR * 24
RATIO =

ET 1440m (24h) in LT is 70m

1440
VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ EorzeaTime

Returns a new instance of EorzeaTime.



15
16
17
18
# File 'lib/eorzea_time.rb', line 15

def initialize(i)
  @epoch = i % 86400
  @time = Time.at(@epoch).utc
end

Class Method Details

.from_time(t) ⇒ Object



11
12
13
# 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

.nowObject



7
8
9
# File 'lib/eorzea_time.rb', line 7

def self.now
  from_time Time.now
end

Instance Method Details

#+(o) ⇒ Object



24
25
26
# File 'lib/eorzea_time.rb', line 24

def +(o)
  self.class.new @epoch + o
end

#-(o) ⇒ Object



28
29
30
# File 'lib/eorzea_time.rb', line 28

def -(o)
  self.class.new @epoch - o
end

#hourObject



32
33
34
# File 'lib/eorzea_time.rb', line 32

def hour
  @time.hour
end

#inspectObject



48
49
50
# File 'lib/eorzea_time.rb', line 48

def inspect
  "#<EorzeaTime #{to_s}>"
end

#last_occurrence(time: Time.now, count: 1) ⇒ Object



71
72
73
74
75
76
77
78
# 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

#minObject



36
37
38
# File 'lib/eorzea_time.rb', line 36

def min
  @time.min
end

#next_occurrence(time: Time.now, count: 1) ⇒ Object



80
81
82
83
84
85
86
87
# 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) ⇒ Object



65
66
67
68
69
# 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

#secObject



40
41
42
# File 'lib/eorzea_time.rb', line 40

def sec
  @time.sec
end

#to_hObject



56
57
58
59
60
61
62
63
# File 'lib/eorzea_time.rb', line 56

def to_h
  {
    i: @epoch,
    hour: hour,
    min: min,
    sec: sec,
  }
end

#to_iObject



20
21
22
# File 'lib/eorzea_time.rb', line 20

def to_i
  @epoch
end

#to_sObject



52
53
54
# File 'lib/eorzea_time.rb', line 52

def to_s
  "%02d:%02d:%02d" % [hour, min, sec]
end

#usecObject



44
45
46
# File 'lib/eorzea_time.rb', line 44

def usec
  @time.usec
end