Class: Darian::Date
Overview
Darian Mars calendar date converter.
mars = Darian::Date.from_earth(Date.today)
puts mars
puts mars.month_name
Instance Attribute Summary
Attributes included from DateMethods
#month, #month_of_season, #season, #since_epoch, #sol, #sol_of_season, #week_sol, #year
Class Method Summary collapse
-
.from_earth(date) ⇒ Object
Return Mars date converted from Earth date.
-
.parse_earth(string) ⇒ Object
Parse Earth date and convert to Mars date.
Instance Method Summary collapse
-
#initialize(time) ⇒ Date
constructor
Create martian date by martian time.
-
#to_s ⇒ Object
Printable string of martian date.
Methods included from DateMethods
#<=>, #month_name, #week_sol_name
Constructor Details
#initialize(time) ⇒ Date
Create martian date by martian time.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/darian/date.rb', line 46 def initialize(time) @since_epoch = time.since_epoch.floor @year = time.year @month = time.month @sol = time.sol @week_sol = time.week_sol @season = time.season @sol_of_season = time.sol_of_season @month_of_season = time.month_of_season end |
Class Method Details
.from_earth(date) ⇒ Object
Return Mars date converted from Earth date.
Darian.from_earth(Date.today)
34 35 36 37 |
# File 'lib/darian/date.rb', line 34 def self.from_earth(date) time = ::Time.parse(date.to_s + " 00:00:00 UTC") Darian::Time.from_earth(time).to_date end |
.parse_earth(string) ⇒ Object
Parse Earth date and convert to Mars date. Shortcut for ‘Darian::Date.from_earth(Date.parse(string))`.
41 42 43 |
# File 'lib/darian/date.rb', line 41 def self.parse_earth(string) self.from_earth(::Date.parse(string)) end |
Instance Method Details
#to_s ⇒ Object
Printable string of martian date.
60 61 62 |
# File 'lib/darian/date.rb', line 60 def to_s sprintf '%d-%02d-%02d', @year, @month, @sol end |