Class: Darian::Date

Inherits:
Object
  • Object
show all
Includes:
DateMethods
Defined in:
lib/darian/date.rb

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, #sol, #sol_of_season, #week_sol, #year

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DateMethods

#month_name, #week_sol_name

Constructor Details

#initialize(time) ⇒ Date

Create martian date by time.



36
37
38
39
40
41
42
43
44
45
# File 'lib/darian/date.rb', line 36

def initialize(time)
  @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



30
31
32
33
# File 'lib/darian/date.rb', line 30

def self.from_earth(date)
  time = ::Time.parse(date.to_s + " 00:00:00")
  ::Darian::Time.from_earth(time).to_date
end

Instance Method Details

#to_sObject

Printable string of martian date.



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

def to_s
  sprintf '%d-%02d-%02d', @year, @month, @sol
end