Class: FFXI::VanaTime

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/Vana/time.rb

Constant Summary

Constants included from Constants

Constants::BASIS_DATE, Constants::DAY, Constants::HOUR, Constants::MINUTE, Constants::MOON_DATE, Constants::MS_BASIS_DATE, Constants::MS_BASIS_VANA, Constants::MS_DAY, Constants::MS_GAME_DAY, Constants::MS_HOUR, Constants::MS_MINUTE, Constants::MS_MOON_DATE, Constants::MS_SECOND

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ VanaTime

Returns a new instance of VanaTime.



5
6
7
# File 'lib/Vana/time.rb', line 5

def initialize(time = Time.now)
  self.earth_time = time
end

Instance Attribute Details

#earth_timeObject

Returns the value of attribute earth_time.



31
32
33
# File 'lib/Vana/time.rb', line 31

def earth_time
  @earth_time
end

Class Method Details

.at(vana_time) ⇒ Object



45
46
47
# File 'lib/Vana/time.rb', line 45

def self.at(vana_time)
  self.new(Time.at(self.vana_to_earth(vana_time)))
end

.nowObject



89
90
91
# File 'lib/Vana/time.rb', line 89

def self.now
  self.new
end

.vana_to_earth(vana_time) ⇒ Object



33
34
35
36
# File 'lib/Vana/time.rb', line 33

def self.vana_to_earth(vana_time)
  (((vana_time.to_f - ((898 * 360 + 30) * MS_DAY.to_f)) / 25) +
      MS_BASIS_DATE.to_f) / MS_SECOND
end

Instance Method Details

#dateObject



65
66
67
# File 'lib/Vana/time.rb', line 65

def date
  @vDate ||= (((@vana_time % (30 * MS_DAY)) / (MS_DAY)) + 1).to_i
end

#dayObject



81
82
83
# File 'lib/Vana/time.rb', line 81

def day
  @vDay ||= VanaDay.new(@vana_time)
end

#hourObject



69
70
71
# File 'lib/Vana/time.rb', line 69

def hour
  @vHour ||= ((@vana_time % MS_DAY) / MS_HOUR).to_i
end

#minuteObject



73
74
75
# File 'lib/Vana/time.rb', line 73

def minute
  @vMin ||= ((@vana_time % MS_HOUR) / MS_MINUTE).to_i
end

#monthObject



61
62
63
# File 'lib/Vana/time.rb', line 61

def month
  @vMon ||= (((@vana_time % (360 * MS_DAY)) / (30 * MS_DAY)) + 1).to_i
end

#moonObject



85
86
87
# File 'lib/Vana/time.rb', line 85

def moon
  @vana_moon ||= VanaMoon.new(@earth_time)
end

#secondObject



77
78
79
# File 'lib/Vana/time.rb', line 77

def second
  @vSec ||= ((@vana_time % MS_MINUTE) / MS_SECOND).to_i
end

#to_fObject



53
54
55
# File 'lib/Vana/time.rb', line 53

def to_f
  @vana_time.to_f
end

#to_iObject



49
50
51
# File 'lib/Vana/time.rb', line 49

def to_i
  @vana_time.to_i
end

#to_sObject



93
94
95
96
# File 'lib/Vana/time.rb', line 93

def to_s
  "#{year}-#{"%02d" % month}-#{"%02d" % date}" +
    " #{"%02d" % hour}:#{"%02d" % minute}:#{"%02d" % second}"
end

#update_instance_variablesObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/Vana/time.rb', line 9

def update_instance_variables
  # the day object knows how to update only what is necessary, so if there
  # is an existing VanaDay object, update it
  if ! @vDay.nil?
    @vDay.vana_time = @vana_time
  end

  # nil these until they're used and updated later
  @vYear=@vMon=@vDate=@vHour=@vMin=@vSec=@vana_moon=nil
end

#vana_time=(vana_time) ⇒ Object



38
39
40
41
42
43
# File 'lib/Vana/time.rb', line 38

def vana_time=(vana_time)
  @vana_time = vana_time.to_f
  @earth_time = Time.at(self.class.vana_to_earth(vana_time))

  update_instance_variables
end

#yearObject



57
58
59
# File 'lib/Vana/time.rb', line 57

def year
  @vYear ||= (@vana_time / (360 * MS_DAY)).to_i
end