Class: Darian::Time
Overview
Darian Mars calendar time converter.
mars = Darian::Time.from_earth(Time.now)
puts mars
puts mars.month_name
Constant Summary collapse
- MARS_TO_EARTH_DAYS =
1.027491251
- EPOCH_OFFSET =
587744.77817
- ROUND_UP_SECOND =
1/86400
Instance Attribute Summary collapse
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#sec ⇒ Object
readonly
Returns the value of attribute sec.
Attributes included from DateMethods
#month, #month_of_season, #season, #sol, #sol_of_season, #week_sol, #year
Class Method Summary collapse
-
.from_earth(time) ⇒ Object
Return Mars time converted from Earth time.
Instance Method Summary collapse
-
#initialize(sols) ⇒ Time
constructor
Create Mars time by sols since 0 year.
-
#to_date ⇒ Object
Return martian date.
-
#to_s ⇒ Object
Printable string of martian time.
Methods included from DateMethods
Constructor Details
#initialize(sols) ⇒ Time
Create Mars time by sols since 0 year.
It is internal contructor. Use ‘Darian.from_earth`.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/darian/time.rb', line 51 def initialize(sols) sD = (sols / 334296).floor doD = (sols - (sD * 334296)).floor sC = 0 doC = doD sC = ((doD - 1) / 66859).floor if doD != 0 doC -= (sC * 66859) + 1 if sC != 0 sX = 0 doX = doC if sC != 0 # century that does not begin with leap day sX = ((doC + 1) / 6686).floor doX -= sX * 6686 - 1 if sX != 0 else sX = (doC / 6686).floor doX -= sX * 6686 if sX != 0 end sII = 0 doII = doX if sC != 0 and sX == 0 # decade that does not begin with leap day sII = (doX / 1337).floor doII -= sII * 1337 if sII != 0 else # 1338, 1337, 1337, 1337 … sII = ((doX - 1) / 1337).floor if doX != 0 doII -= (sII * 1337 + 1) if sII != 0 end sI = 0 doI = doII if sII == 0 and (sX != 0 or (sX == 0 and sC == 0)) sI = (doII / 669).floor doI -= 669 if sI != 0 else # 668, 669 sI = ((doII + 1) / 669).floor doI -= 668 if sI != 0 end @year = 500 * sD + 100 * sC + 10 * sX + 2 * sII + sI @season = if doI < 167 0 elsif doI < 334 1 elsif doI < 501 2 else 3 end @sol_of_season = doI - 167 * @season @month_of_season = (@sol_of_season / 28).floor @month = @month_of_season + 6 * @season + 1 @sol = doI - ((@month - 1) * 28 - @season) + 1 @week_sol = (@sol - 1) % 7 + 1 hour = (sols - sols.floor) * 24 min = (hour - hour.floor) * 60 @hour = hour.floor @min = min.floor @sec = ((min - min.floor) * 60).floor end |
Instance Attribute Details
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
34 35 36 |
# File 'lib/darian/time.rb', line 34 def hour @hour end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
35 36 37 |
# File 'lib/darian/time.rb', line 35 def min @min end |
#sec ⇒ Object (readonly)
Returns the value of attribute sec.
36 37 38 |
# File 'lib/darian/time.rb', line 36 def sec @sec end |
Class Method Details
.from_earth(time) ⇒ Object
Return Mars time converted from Earth time.
Darian.from_earth(Time.now)
41 42 43 44 45 46 |
# File 'lib/darian/time.rb', line 41 def self.from_earth(time) # 719527 is days until 0 year for Unix Epoch days = (time.to_i / 86400.0) + 719527 sols = (days - EPOCH_OFFSET) / MARS_TO_EARTH_DAYS self.new(sols) end |
Instance Method Details
#to_date ⇒ Object
Return martian date.
123 124 125 |
# File 'lib/darian/time.rb', line 123 def to_date ::Darian::Date.new(self) end |
#to_s ⇒ Object
Printable string of martian time.
117 118 119 120 |
# File 'lib/darian/time.rb', line 117 def to_s sprintf '%d-%02d-%02d %02d:%02d:%02d', @year, @month, @sol, @hour, @min, @sec end |