darian_calendar 0.1.0 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OThlODFjMThlMDdmN2U4YzBmYTk1MGQxNjI0MzFmMzhkZmVjNWZhNA==
4
+ NGFkYjZjZDk2Y2MwYzA4M2NhNDI4MDczYzEzODJiNjI2ZTk4YmJjNw==
5
5
  data.tar.gz: !binary |-
6
- OWZmZDg5ZWE3MWE0YWQyMzQ0NWNkMWQ4Y2YwZjQ2YzM0MDVlYmZjNQ==
6
+ MmNlMjdmZDQ3ZDk1ZDNmZThmNDM0YjUxY2JhM2U5M2RhOWYyMmJjMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTA3MjExNWMxYTEwYjgxZjkxYzU3MzIyNTUwYjMyYWY3YWFjY2RjNGM4MzQw
10
- MTYwNzEzN2RjYjYzMTIyNGIyMjdhNzU5ZTgzOWU3ZGVmNTMzZjA3NTBmNmM4
11
- ZDBiNWNiYWJjNGJiYjc4NzI0MDYxZjg5NjVhZDM1OGM1YWM5OGM=
9
+ MzkyNTQ3NmJlNWUyZTEzMzJhYTUzZjBkODcwMDQ3OWYyYWU4ZmY4M2Y0YTgx
10
+ MWNiODg0MGQ1ZDg3YWM3ZTdjNmM2YjQwNTJkM2RkOGI0YWUxZGZmNDBmMGM4
11
+ OTcxMTk2M2IwYzI0MWFiN2Q0ZTBjZDNmZTBkNjYxNzQ0MTE0OTU=
12
12
  data.tar.gz: !binary |-
13
- ZTY3Y2I5NzBkZjBmOTYxYWE5ZjI5MGEyYmE3YTQzMmFlNjQwNTE1ZjBkMDM2
14
- NTEwYjQ2NTQ4MjY3ZGJiN2FjNWMwNTJiYWQ2MjA3MGNlNjUyN2I2ZTIzNGY4
15
- OTE3OWU5ZWNkNzJlNDg4YTEwOTIzMWRlNGE0YzYyOTIxMmE0MzI=
13
+ M2EyMmNhZmNmZGViYWY5ZWFmODEzYTUwNTljODAyMjgxNjQxMDExMTFlOWIx
14
+ YzlmNzFiZTllZTExYmRlMGMwMzcwYmEzMDQ5Y2IzNDgyY2YzOTgzYTI5NTJi
15
+ Yjg5MzE4OTFkMzAyNDg0YzA4NjgwYjY5YTFlMjQ0YzJmOTgxZGQ=
data/.gitignore CHANGED
@@ -2,6 +2,8 @@ pkg
2
2
  rdoc
3
3
  doc
4
4
  .yardoc
5
+ .ruby-version
6
+ .ruby-gemset
5
7
  .DS_Store
6
8
  .idea/*
7
9
  *.sh
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour --format doc
1
+ --color --format doc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2
2
+
3
+ - Documentation with Yard
4
+ - Minor optimization
5
+
1
6
  ## 0.1.0
2
7
 
3
8
  - Working version of the darian calender converter
data/Gemfile CHANGED
@@ -1,5 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ group :development do
4
+ gem 'yard'
5
+ gem 'redcarpet'
6
+ end
7
+
3
8
  group :development, :test do
4
9
  gem 'rake'
5
10
  end
data/README.md CHANGED
@@ -7,7 +7,7 @@ It was created by aerospace engineer and political scientist Thomas Gangale in 1
7
7
 
8
8
  This Ruby library converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system; _Martiana_, _Defrost_, _Areosynchronous_, _Hensel_ and _Aqua_.
9
9
 
10
- It's based on the [JavaScript Converter] by Thomas Gangale.
10
+ It's based on the [JavaScript Converter] which was developed by Alan Hensel and Thomas Gangale.
11
11
 
12
12
  [Wikipedia]: http://en.wikipedia.org/wiki/Darian_calendar
13
13
  [Darian calendar]: http://en.wikipedia.org/wiki/Darian_calendar
@@ -15,8 +15,14 @@ It's based on the [JavaScript Converter] by Thomas Gangale.
15
15
 
16
16
  ## Installation
17
17
 
18
+ In Bundler:
18
19
  ```ruby
19
- gem 'darian_calendar', :git => 'git://github.com/marsec/darian_calendar.git'
20
+ gem "darian_calendar"
21
+ ```
22
+
23
+ Otherwise:
24
+ ```bash
25
+ [sudo|rvm] gem install darian_calendar
20
26
  ```
21
27
 
22
28
  ## Usage
@@ -82,6 +88,9 @@ Unit tests are provided for all of Darian Calendar's methods:
82
88
  bundle exec rspec
83
89
  ```
84
90
 
85
- ## License
91
+ ## Copyright
92
+ - _The Darian Calendar Ruby Gem_ is Copyright © 2014 Christian Worreschk, MarSec.
93
+ - _The Darian System_ is Copyright © 1986-2005 by Thomas Gangale
86
94
 
95
+ ## License
87
96
  This Darian Calendar Ruby Gem is released under the [European Union Public Licence V. 1.1](http://opensource.org/licenses/EUPL-1.1).
@@ -2,12 +2,18 @@
2
2
 
3
3
  require 'darian_calendar/time'
4
4
 
5
+ # This Ruby library converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system; Martiana, Defrost, Areosynchronous, Hensel and Aqua.
6
+ # See http://github.com/marsec/darian_calendar for more Information.
7
+ # It's based on the JavaScript Converter which was developed by Alan Hensel and Thomas Gangale. (http://pweb.jps.net/~tgangale/mars/converter/calendar_clock.htm)
5
8
  module DarianCalendar
6
9
 
7
10
  class << self
8
11
 
9
- def now
10
- DarianCalendar::Time.now
12
+ # Returns the current mars time. Shortcut for 'DarianCalendar::Time.now'
13
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
14
+ # @return [DarianCalendar::Time] current mars time
15
+ def now(type=CalendarTypes::MARTIANA)
16
+ DarianCalendar::Time.now(type)
11
17
  end
12
18
 
13
19
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module DarianCalendar
4
4
 
5
+ # Variantes of the Darian calendar system
5
6
  module CalendarTypes
6
7
  MARTIANA = :martiana
7
8
  DEFROST = :defrost
@@ -10,86 +11,108 @@ module DarianCalendar
10
11
  AQUA = :aqua
11
12
  end
12
13
 
14
+ # Timestamp in the Darian calendar system
13
15
  class Time
14
16
  include Comparable
15
17
 
16
- #<editor-fold desc="Attributes">
17
-
18
+ # @return [Integer] year
18
19
  attr_reader :year
20
+ # @return [Integer] month of the year
19
21
  attr_reader :month
22
+ # @return [Integer] sol of the month
20
23
  attr_reader :sol
21
-
24
+ # @return [Integer] hour of the sol
22
25
  attr_reader :hour
26
+ # @return [Integer] minute of the hour
23
27
  attr_reader :min
28
+ # @return [Integer] second of the minute
24
29
  attr_reader :sec
25
-
30
+ # @return [String] full month name ("Mithuna")
26
31
  attr_reader :month_name
32
+ # @return [String] full weeksol name ("Sol Jovis")
27
33
  attr_reader :week_sol_name
28
-
34
+ # @return [Float] number of sols (with hour, minutes and seconds) since the earth date 0-0-0
29
35
  attr_reader :total_sols
36
+ # @return [String] sol of the week
30
37
  attr_reader :week_sol
38
+ # @return [Integer] season of the year
31
39
  attr_reader :season
40
+ # @return [Integer] sol of the season
32
41
  attr_reader :sol_of_season
42
+ # @return [Integer] month of the season
33
43
  attr_reader :month_of_season
44
+ # @return [Integer] sol of the year
34
45
  attr_reader :sol_of_year
35
-
46
+ # @return [String] name of the calendar type ("Martiana")
36
47
  attr_reader :calendar_type
37
48
 
38
49
  alias :day :sol
39
50
  alias :week_day :week_sol
40
51
 
41
- #</editor-fold>
42
-
43
- #<editor-fold desc="Constants">
44
-
45
52
  MARS_TO_EARTH_DAYS = 1.027491251
46
53
  EPOCH_OFFSET = 587744.77817
47
54
  SECONDS_A_DAY = 86400.0
48
55
  ROUND_UP_SECOND = 1/SECONDS_A_DAY;
49
56
  E_DAYS_TIL_UNIX = 719527.0
50
57
 
51
- SOL_MARTIANA = ['', 'Sol Solis', 'Sol Lunae', 'Sol Martis', 'Sol Mercurii', 'Sol Jovis', 'Sol Veneris', 'Sol Saturni']
52
- SOL_DEFROST = ['', 'Axatisol', 'Benasol', 'Ciposol', 'Domesol', 'Erjasol', 'Fulisol', 'Gavisol']
53
- SOL_AREOSYNCHRONOUS = ['', 'Heliosol', 'Phobosol', 'Deimosol', 'Terrasol', 'Venusol', 'Mercurisol', 'Jovisol']
54
-
55
- MONTH_MARTIANA = ['', 'Sagittarius', 'Dhanus', 'Capricornus', 'Makara', 'Aquarius', 'Kumbha', 'Pisces', 'Mina', 'Aries', 'Mesha', 'Taurus', 'Rishabha', 'Gemini', 'Mithuna', 'Cancer', 'Karka', 'Leo', 'Simha', 'Virgo', 'Kanya', 'Libra', 'Tula', 'Scorpius', 'Vrishika']
56
- MONTH_DEFROST = ['', 'Adir', 'Bora', 'Coan', 'Deti', 'Edal', 'Flo', 'Geor', 'Heliba', 'Idanon', 'Jowani', 'Kireal', 'Larno', 'Medior', 'Neturima', 'Ozulikan', 'Pasurabi', 'Rudiakel', 'Safundo', 'Tiunor', 'Ulasja', 'Vadeun', 'Wakumi', 'Xetual', 'Zungo']
57
- MONTH_HENSEL = ['', 'Vernalis', 'Duvernalis', 'Trivernalis', 'Quadrivernalis', 'Pentavernalis', 'Hexavernalis', 'Aestas', 'Duestas', 'Triestas', 'Quadrestas', 'Pentestas', 'Hexestas', 'Autumnus', 'Duautumn', 'Triautumn', 'Quadrautumn', 'Pentautumn', 'Hexautumn', 'Unember', 'Duember', 'Triember', 'Quadrember', 'Pentember', 'Hexember']
58
-
59
- #</editor-fold>
60
-
61
- #<editor-fold desc="Class Methods">
62
-
58
+ SOL_NAMES = {
59
+ martiana: ['Sol Solis', 'Sol Lunae', 'Sol Martis', 'Sol Mercurii', 'Sol Jovis', 'Sol Veneris', 'Sol Saturni'],
60
+ defrost: ['Axatisol', 'Benasol', 'Ciposol', 'Domesol', 'Erjasol', 'Fulisol', 'Gavisol'],
61
+ areosynchronous: ['Heliosol', 'Phobosol', 'Deimosol', 'Terrasol', 'Venusol', 'Mercurisol', 'Jovisol']
62
+ }
63
+ MONTH_NAMES = {
64
+ martiana: ['Sagittarius', 'Dhanus', 'Capricornus', 'Makara', 'Aquarius', 'Kumbha', 'Pisces', 'Mina', 'Aries', 'Mesha', 'Taurus', 'Rishabha', 'Gemini', 'Mithuna', 'Cancer', 'Karka', 'Leo', 'Simha', 'Virgo', 'Kanya', 'Libra', 'Tula', 'Scorpius', 'Vrishika'],
65
+ defrost: ['Adir', 'Bora', 'Coan', 'Deti', 'Edal', 'Flo', 'Geor', 'Heliba', 'Idanon', 'Jowani', 'Kireal', 'Larno', 'Medior', 'Neturima', 'Ozulikan', 'Pasurabi', 'Rudiakel', 'Safundo', 'Tiunor', 'Ulasja', 'Vadeun', 'Wakumi', 'Xetual', 'Zungo'],
66
+ hensel: ['Vernalis', 'Duvernalis', 'Trivernalis', 'Quadrivernalis', 'Pentavernalis', 'Hexavernalis', 'Aestas', 'Duestas', 'Triestas', 'Quadrestas', 'Pentestas', 'Hexestas', 'Autumnus', 'Duautumn', 'Triautumn', 'Quadrautumn', 'Pentautumn', 'Hexautumn', 'Unember', 'Duember', 'Triember', 'Quadrember', 'Pentember', 'Hexember']
67
+ }
68
+
69
+ # Calculates the total number of martian sols for this earth time
70
+ # @param earth_time [Time] Earth time
71
+ # @return [Integer] number of sols
63
72
  def self.sols_from_earth_time(earth_time)
64
73
  days = (earth_time.to_f / SECONDS_A_DAY) + E_DAYS_TIL_UNIX
65
74
  sols = (days - EPOCH_OFFSET) / MARS_TO_EARTH_DAYS
66
75
  return sols
67
76
  end
68
77
 
78
+ # Converts a time object to a mars time object
79
+ # @param earth_time [Time] Earth time
80
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
81
+ # @return [DarianCalendar::Time] mars time
69
82
  def self.from_earth(earth_time, type=CalendarTypes::MARTIANA)
70
83
  self.new(self.sols_from_earth_time(earth_time), type)
71
84
  end
72
85
 
86
+ # Parses the given representation of date and time, and converts it to mars time
87
+ # @param string [String] String with date and time
88
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
89
+ # @return [DarianCalendar::Time] mars time
73
90
  def self.parse_earth(string, type=CalendarTypes::MARTIANA)
74
91
  self.from_earth(::Time.parse(string), type)
75
92
  end
76
93
 
94
+ # Returns the current mars time.
95
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
96
+ # @return [DarianCalendar::Time] current mars time
77
97
  def self.now(type=CalendarTypes::MARTIANA)
78
98
  self.from_earth(::Time.now, type)
79
99
  end
80
100
 
81
- #</editor-fold>
82
-
83
- #<editor-fold desc="Instance Methods">
84
-
101
+ # Compares two times and returns -1, zero, 1 or nil. The other should be a mars time object.
102
+ # @param another [DarianCalendar::Time]
103
+ # @return [Integer] Compare result
85
104
  def <=>(another)
86
105
  @total_sols <=> another.total_sols
87
106
  end
88
107
 
108
+ # Return the number of sols in the given year
109
+ # @return [Integer] Number of sols in the given year
89
110
  def sols_in_year
90
111
  self.leap? ? 669 : 668
91
112
  end
92
113
 
114
+ # Returns true if the given year is a leap year
115
+ # @return [Boolean] true if the given year is a leap year
93
116
  def leap?
94
117
  return true if (@year % 500) == 0
95
118
  return false if (@year % 100) == 0
@@ -98,16 +121,24 @@ module DarianCalendar
98
121
  return true
99
122
  end
100
123
 
124
+ # Converts the given mars time to earth time
125
+ # @return [Time] earth time
101
126
  def to_earth
102
127
  earth_days = (@total_sols * MARS_TO_EARTH_DAYS) + EPOCH_OFFSET + ROUND_UP_SECOND
103
128
  earth_seconds = ((earth_days - E_DAYS_TIL_UNIX) * SECONDS_A_DAY) - 1
104
129
  ::Time.at(earth_seconds)
105
130
  end
106
131
 
132
+ # Returns a string in an ISO 8601 format (This method doesn’t use the expanded representations).
133
+ # @return [String] Time as a string in an ISO 8601 format
107
134
  def to_s
108
135
  sprintf('%d-%02d-%02d %02d:%02d:%02d', @year, @month, @sol, @hour, @min, @sec)
109
136
  end
110
137
 
138
+ # Converts a number of martian sols to mars time.
139
+ # @param sols optional [Float] Number of martian sols. Default is the number of sols of the the current time.
140
+ # @param type optional [DarianCalendar::CalendarTypes] calendar type.
141
+ # @return [DarianCalendar::Time] mars time
111
142
  def initialize(sols=nil, type=CalendarTypes::MARTIANA)
112
143
  @calendar_type = type.to_s.capitalize
113
144
  @total_sols = sols.to_f != 0 ? sols.to_f : self.sols_from_earth_time(::Time.now)
@@ -167,17 +198,17 @@ module DarianCalendar
167
198
  @week_sol = ((@sol - 1) % 7) + 1 # 1-7
168
199
 
169
200
  @week_sol_name = case type
170
- when CalendarTypes::MARTIANA, CalendarTypes::HENSEL then SOL_MARTIANA[@week_sol]
171
- when CalendarTypes::DEFROST then SOL_DEFROST[@week_sol]
172
- when CalendarTypes::AREOSYNCHRONOUS then SOL_AREOSYNCHRONOUS[@week_sol]
201
+ when CalendarTypes::MARTIANA, CalendarTypes::HENSEL then SOL_NAMES[:martiana][@week_sol-1]
202
+ when CalendarTypes::DEFROST then SOL_NAMES[:defrost][@week_sol-1]
203
+ when CalendarTypes::AREOSYNCHRONOUS then SOL_NAMES[:areosynchronous][@week_sol-1]
173
204
  when CalendarTypes::AQUA then @week_sol.to_s
174
205
  else ''
175
206
  end
176
207
 
177
208
  @month_name = case type
178
- when CalendarTypes::MARTIANA then MONTH_MARTIANA[@month]
179
- when CalendarTypes::DEFROST, CalendarTypes::AREOSYNCHRONOUS then MONTH_DEFROST[@month]
180
- when CalendarTypes::HENSEL then MONTH_HENSEL[@month]
209
+ when CalendarTypes::MARTIANA then MONTH_NAMES[:martiana][@month-1]
210
+ when CalendarTypes::DEFROST, CalendarTypes::AREOSYNCHRONOUS then MONTH_NAMES[:defrost][@month-1]
211
+ when CalendarTypes::HENSEL then MONTH_NAMES[:hensel][@month-1]
181
212
  when CalendarTypes::AQUA then @month.to_s
182
213
  else ''
183
214
  end
@@ -191,7 +222,5 @@ module DarianCalendar
191
222
  @sec = ((min - min.floor) * 60).floor
192
223
  end
193
224
 
194
- #</editor-fold>
195
-
196
225
  end
197
226
  end
@@ -1,3 +1,3 @@
1
1
  module DarianCalendar
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2'
3
3
  end
data/spec/time_spec.rb CHANGED
@@ -78,7 +78,7 @@ describe DarianCalendar::Time do
78
78
  end
79
79
 
80
80
  describe '#sols_in_year' do
81
- it 'returns the count of sols in a martian year' do
81
+ it 'returns the number of sols in a martian year' do
82
82
  leap_mars_time = DarianCalendar::Time.from_earth(Time.utc(2013, 10, 15, 16, 50, 0))
83
83
  leap_mars_time.sols_in_year.should == 669
84
84
  @mars_time.sols_in_year.should == 668
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darian_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Worreschk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This Ruby library converts earth time to mars time and back again. You
14
14
  can choose between 5 variants of the Darian calendar system; Martiana, Defrost,
@@ -63,3 +63,4 @@ specification_version: 4
63
63
  summary: Converts earth time to mars time and back again. You can choose between 5
64
64
  variants of the Darian calendar system.
65
65
  test_files: []
66
+ has_rdoc: