class Snafu::Models::GlitchTime
Class representing a Glitch date and time
there are 4435200 real seconds in a game year there are 115200 real seconds in a game week there are 14400 real seconds in a game day there are 600 real seconds in a game hour there are 10 real seconds in a game minute
Constants
- DAYS_IN_MONTH
- DAY_NAMES
- D_SECS
- GLITCH_EPOCH
- H_SECS
- MONTH_NAMES
- M_SECS
- Y_SECS
Attributes
seconds_since_epoch[R]
timestamp[R]
Public Class Methods
new(new_timestamp = Time.now)
click to toggle source
# File lib/snafu/models/glitch_time.rb, line 25 def initialize(new_timestamp = Time.now) @timestamp = new_timestamp.to_i raise InvalidTimestampError if @timestamp < GLITCH_EPOCH @timestamp = timestamp @seconds_since_epoch = @timestamp - GLITCH_EPOCH end
Public Instance Methods
day_of_month()
click to toggle source
Returns the 0-based day of the month
# File lib/snafu/models/glitch_time.rb, line 57 def day_of_month return self.day_of_year if self.month == 0 self.day_of_year - DAYS_IN_MONTH.slice(0, (month)).inject(:+) end
day_of_week()
click to toggle source
Returns the 0-based day of the week
# File lib/snafu/models/glitch_time.rb, line 63 def day_of_week return -1 if day_of_year == 307 days_since_epoch % 8 end
day_of_year()
click to toggle source
Returns the 0-based day of the current Glitch year
# File lib/snafu/models/glitch_time.rb, line 38 def day_of_year (seconds_since_start_of_year / D_SECS).to_i end
days_since_epoch()
click to toggle source
Returns the number of game days since epoch
# File lib/snafu/models/glitch_time.rb, line 74 def days_since_epoch self.day_of_year + (307 * year) end
hour()
click to toggle source
Returns the hour of the day
# File lib/snafu/models/glitch_time.rb, line 79 def hour # seconds_since_start_of_day / H_SECS (seconds_since_start_of_day / H_SECS).to_i end
minute(padded = false)
click to toggle source
Returns the minute of the hour
Options¶ ↑
:padded
- If true, will return a zero-padded string if the minute value is less than 10
# File lib/snafu/models/glitch_time.rb, line 89 def minute(padded = false) min = (seconds_since_start_of_hour / M_SECS).to_i if padded && min < 10 min = "0#{min}" end min end
month()
click to toggle source
Returns the 0-based month of the year
# File lib/snafu/models/glitch_time.rb, line 43 def month running_days = -1 DAYS_IN_MONTH.each_with_index do |days, idx| running_days += days return idx if day_of_year <= running_days end end
name_of_day()
click to toggle source
Returns the name of the day
# File lib/snafu/models/glitch_time.rb, line 69 def name_of_day DAY_NAMES[day_of_week] end
name_of_month()
click to toggle source
Returns the name of the month
# File lib/snafu/models/glitch_time.rb, line 52 def name_of_month MONTH_NAMES[self.month] end
to_s()
click to toggle source
# File lib/snafu/models/glitch_time.rb, line 97 def to_s "#{self.hour}:#{self.minute(padded: true)}, #{self.name_of_day} #{self.day_of_month + 1} of #{self.name_of_month}, year #{self.year}" end
year()
click to toggle source
Returns the number of years since the Glitch epoch
# File lib/snafu/models/glitch_time.rb, line 33 def year (seconds_since_epoch / Y_SECS).to_i end
Private Instance Methods
seconds_since_start_of_day()
click to toggle source
# File lib/snafu/models/glitch_time.rb, line 106 def seconds_since_start_of_day seconds_since_start_of_year - (D_SECS * self.day_of_year) end
seconds_since_start_of_hour()
click to toggle source
# File lib/snafu/models/glitch_time.rb, line 110 def seconds_since_start_of_hour seconds_since_start_of_day - (H_SECS * self.hour) end
seconds_since_start_of_year()
click to toggle source
# File lib/snafu/models/glitch_time.rb, line 102 def seconds_since_start_of_year seconds_since_epoch - (Y_SECS * self.year) end