darian_calendar 1.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmY2MWYxMTY4NGFjODBhZjE4MTJjZTljMzQ5NDVkNGNlOGQ5ZDI3NA==
4
+ YjgyMGVjYTc4YTFlZTMzMDdkOTdjZTFlMDVkOGJhZGZmYzZhOWVmNg==
5
5
  data.tar.gz: !binary |-
6
- NTY0MWU1OWUzOWVkNDcyM2EyM2E1OGUyNTZhMmE4ODJjZGQxZDM2NA==
6
+ ZmZhMDExOWRlM2NlZWQ4NDY5NTBjZTI4MzUyMzMzOTcxNjViNzExNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTI4M2QwYmQzZDY1ZTE3ZmU4MmVkYjE0ODI2OTNiYzcyYTgyMTZiZGI2NjQw
10
- YzhmNWNiOGEwYzk3N2Q2NTFhM2IwYWNjYzUyZTc0MTg1ZjA2MDdhNDdjYWRl
11
- YzkxZTQyMGZmYzczYzEwOTcwN2ZlMmQwZDQ4MTE0YjU2ZDhjM2M=
9
+ Mjg1YzA2NGJhMTUwNzdmYjVmOGVkYWZhYzEzNWNlN2E5ZTQ4NTViNTQxYTdj
10
+ ODM3OWUzNmZlZGNhZjFjYWQyYmVmZDAwOTI5MTAwMDg3N2JhZDc3NWYzYzgz
11
+ Yjg0NDMwYTEzMTZhOTQ1MWRmZWYyNjg4MTllNmQ3ZjFiYzcxMjM=
12
12
  data.tar.gz: !binary |-
13
- YmUxYWIwYTBlNWY4OWYyM2JkZmI0YWFkMzZjODZkZmMxZGQ0MGZiODdhMTEz
14
- MmYwYTMwMzJlYmQ2MWIzMmVmZmIyMTBkZTg5NzZjZjYzM2Y5ZGIyYTE5ZTFm
15
- ZDdlNzhjNWJkNGQzODcwNjQ4NDBmZWNhY2E0YTM2MzMzNWZjNWU=
13
+ YjA5ZDQ0YjI2NDMyYTUxZWNiYTIyMmY5ZmVjMmE0MTFlOTJhMmM1NmM1M2I0
14
+ ZDEzMzQ5MzljZDBjY2E2YzA0NzM0NDY0NGYxZWY1ZGMxMzViMmNmM2NmZmIw
15
+ M2MzNjA4MDMxMDBmMTYxNTQxNTkxYmRhYzUyMDE4NGQzNDBjNTY=
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  pkg
2
2
  rdoc
3
3
  doc
4
+ coverage
4
5
  .yardoc
5
6
  .ruby-version
6
7
  .ruby-gemset
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color --format doc
1
+ --color
@@ -1,8 +1,15 @@
1
1
  language: ruby
2
+
2
3
  rvm:
4
+ - 1.9.2
3
5
  - 1.9.3
4
6
  - 2.0.0
5
7
  - 2.1.0
6
8
  - jruby
7
9
  - rbx
10
+
8
11
  bundler_args: --without development
12
+
13
+ branches:
14
+ only:
15
+ - master
@@ -0,0 +1,6 @@
1
+ --title 'Darian Calendar'
2
+ --readme README.md
3
+ --no-private
4
+ --charset utf-8
5
+ --markup=markdown
6
+ 'lib/**/*.rb' - '*.md'
@@ -1,3 +1,6 @@
1
+ ## 1.1.0
2
+ - Create Date and Time objects with by year, month, sol (hour, minute, second)
3
+
1
4
  ## 1.0
2
5
  - JSON support
3
6
  - Martian date object
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ end
11
11
 
12
12
  group :test do
13
13
  gem 'rspec'
14
+ gem 'simplecov'
14
15
  end
15
16
 
16
17
  platforms :rbx do
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Darian Calendar
2
2
 
3
- [![Build Status](https://travis-ci.org/marsec/darian_calendar.png)](https://travis-ci.org/marsec/darian_calendar)
3
+ [![Gem Version](https://badge.fury.io/rb/darian_calendar.png)](http://badge.fury.io/rb/darian_calendar) [![Build Status](https://travis-ci.org/marsec/darian_calendar.png)](https://travis-ci.org/marsec/darian_calendar)
4
4
 
5
5
  _The [Darian calendar] is a proposed system of time-keeping designed to serve the needs of any possible future human settlers on the planet Mars.
6
6
  It was created by aerospace engineer and political scientist Thomas Gangale in 1985 and named by him after his son Darius._ ([Wikipedia])
@@ -82,6 +82,18 @@ DarianCalendar::CalendarTypes::HENSEL
82
82
  DarianCalendar::CalendarTypes::AQUA
83
83
  ```
84
84
 
85
+ ## Supported Ruby Interpreters
86
+
87
+ This library aims to support and is [tested](https://travis-ci.org/marsec/darian_calendar) against the following Ruby interpreters and versions:
88
+
89
+ - MRI 1.9.2
90
+ - MRI 1.9.3
91
+ - MRI 2.0.0
92
+ - MRI 2.1.0
93
+ - JRuby
94
+ - Rubinius
95
+
96
+
85
97
  ## Testing
86
98
 
87
99
  Unit tests are provided for all of Darian Calendar's methods:
data/Rakefile CHANGED
@@ -13,5 +13,5 @@ task :default => :spec
13
13
 
14
14
  require 'rspec/core/rake_task'
15
15
  RSpec::Core::RakeTask.new do |t|
16
- t.rspec_opts = ['--color', '--format doc']
16
+ t.rspec_opts = ['--color']
17
17
  end
@@ -3,21 +3,22 @@
3
3
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
4
  require 'darian_calendar/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = 'darian_calendar'
8
- s.version = DarianCalendar::VERSION
9
- s.date = Time.now.strftime('%Y-%m-%d')
10
- s.platform = Gem::Platform::RUBY
11
- s.summary = 'Converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system.'
12
- s.description = '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
+ Gem::Specification.new do |gem|
7
+ gem.name = 'darian_calendar'
8
+ gem.version = DarianCalendar::VERSION
9
+ gem.date = Time.now.strftime('%Y-%m-%d')
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.summary = 'Converts earth time to mars time and back again. You can choose between 5 variants of the Darian calendar system.'
12
+ gem.description = '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.'
13
13
 
14
- s.authors = ['Christian Worreschk']
15
- s.email = ['info@marsec.de']
16
- s.homepage = 'http://github.com/marsec/darian_calendar'
17
- s.licenses = ['EUPL-1.1']
14
+ gem.authors = ['Christian Worreschk']
15
+ gem.email = ['info@marsec.de']
16
+ gem.homepage = 'http://github.com/marsec/darian_calendar'
17
+ gem.licenses = ['EUPL-1.1']
18
18
 
19
- s.require_paths = ['lib']
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {spec}/*`.split("\n")
22
- s.extra_rdoc_files = ['README.md', 'LICENSE.md', 'CHANGELOG.md']
19
+ gem.require_paths = ['lib']
20
+ gem.files = `git ls-files`.split("\n")
21
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
22
+ gem.extra_rdoc_files = ['README.md', 'LICENSE.md', 'CHANGELOG.md']
23
+ gem.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'Darian Calendar']
23
24
  end
@@ -63,6 +63,18 @@ module DarianCalendar
63
63
  DarianCalendar::Date.today(type)
64
64
  end
65
65
 
66
+ # Returns true if the given martian year is a leap year
67
+ # @param year [Integer] martian year
68
+ # @return [Boolean] true if the given year is a leap year
69
+ def is_mars_leap_year?(year)
70
+ return false if year.nil?
71
+ return true if (year % 500) == 0
72
+ return false if (year % 100) == 0
73
+ return true if (year % 10) == 0
74
+ return false if (year % 2) == 0
75
+ return true
76
+ end
77
+
66
78
  end
67
79
 
68
80
  end
@@ -36,6 +36,9 @@ module DarianCalendar
36
36
 
37
37
  protected
38
38
 
39
+ # Set all attributes by the number of martian sols and calendar type
40
+ # @param total_sols [Float] Total number of martian sols
41
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
39
42
  def set_attributes(total_sols, type)
40
43
  @calendar_type = type.to_s.capitalize
41
44
  @total_sols = total_sols
@@ -137,7 +140,7 @@ module DarianCalendar
137
140
  end
138
141
 
139
142
  # Sets the model attributes from a JSON string. Returns self.
140
- # @param json [String] JSON string
143
+ # @param string [String] JSON string
141
144
  # @return [DarianCalendar::Date] mars date
142
145
  def self.from_json(string)
143
146
  json = JSON::parse(string)
@@ -145,6 +148,31 @@ module DarianCalendar
145
148
  self.new(json['total_sols'].to_f, type)
146
149
  end
147
150
 
151
+ # Creates a date object by year, month and sol.
152
+ # If you pass the year with nothing else time will default to the first month 1 of that year.
153
+ # @param year [Integer] year
154
+ # @param month [Integer] month
155
+ # @param sol [Integer] sol
156
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
157
+ # @return [DarianCalendar::Date] mars date
158
+ def self.by_digits(year=nil, month=1, sol=1, type=DarianCalendar::CalendarTypes::MARTIANA)
159
+ if year.nil?
160
+ raise ArgumentError, 'Invalid year'
161
+ end
162
+ if (month < 1) || (month >24)
163
+ raise ArgumentError, 'Invalid month'
164
+ end
165
+ if (sol < 1) || (sol > 28)
166
+ raise ArgumentError, 'Invalid sol'
167
+ end
168
+ if ((month % 6) == 0) && (sol == 28) && !((month == 24) && DarianCalendar::is_mars_leap_year?(year))
169
+ raise ArgumentError, 'Invalid sol for this month'
170
+ end
171
+
172
+ sols = sol + ((month-1) * 28) - ((month-1)/6).floor + 668 * year + (year / 2).floor + ((year-1) / 10).floor - ((year-1) / 100).floor + ((year-1) / 1000).floor
173
+ return self.new(sols)
174
+ end
175
+
148
176
  # Compares two dates and returns -1, zero, 1 or nil. The other should be a mars date object.
149
177
  # @param another [DarianCalendar::Date]
150
178
  # @return [Integer] Compare result
@@ -161,11 +189,7 @@ module DarianCalendar
161
189
  # Returns true if the given year is a leap year
162
190
  # @return [Boolean] true if the given year is a leap year
163
191
  def leap?
164
- return true if (@year % 500) == 0
165
- return false if (@year % 100) == 0
166
- return true if (@year % 10) == 0
167
- return false if (@year % 2) == 0
168
- return true
192
+ DarianCalendar::is_mars_leap_year?(@year)
169
193
  end
170
194
 
171
195
  # Converts the given mars date to earth date
@@ -205,7 +229,7 @@ module DarianCalendar
205
229
  # @return [DarianCalendar::Date] mars date
206
230
  def initialize(sols=nil, type=DarianCalendar::CalendarTypes::MARTIANA)
207
231
  total_sols = sols.to_f != 0 ? sols.to_f : DarianCalendar.sols_from_earth(::Date.today)
208
- self.set_attributes(total_sols, type)
232
+ self.set_attributes(total_sols.floor, type)
209
233
  end
210
234
 
211
235
  end
@@ -28,6 +28,13 @@ module DarianCalendar
28
28
  self.from_earth(::Time.parse(string), type)
29
29
  end
30
30
 
31
+ # Creates a date object denoting the present mars day.
32
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
33
+ # @return [DarianCalendar::Time] current mars date as time object
34
+ def self.today(type=DarianCalendar::CalendarTypes::MARTIANA)
35
+ self.new(DarianCalendar::Date.today.total_sols)
36
+ end
37
+
31
38
  # Returns the current mars time.
32
39
  # @param type [DarianCalendar::CalendarTypes] Calendar type
33
40
  # @return [DarianCalendar::Time] current mars time
@@ -35,6 +42,39 @@ module DarianCalendar
35
42
  self.from_earth(::Time.now, type)
36
43
  end
37
44
 
45
+ # Creates a date object by year, month, sol, hour, minute and second.
46
+ # If you pass the year with nothing else time will default to the first month 1 of that year at 00:00:00.
47
+ # @param year [Integer] year
48
+ # @param month [Integer] month
49
+ # @param month [Integer] sol
50
+ # @param month [Integer] hour
51
+ # @param month [Integer] minute
52
+ # @param sol [Integer] second
53
+ # @param type [DarianCalendar::CalendarTypes] Calendar type
54
+ # @return [DarianCalendar::Time] mars time
55
+ def self.by_digits(year=nil, month=1, sol=1, hour=0, minute=0, second=0, type=DarianCalendar::CalendarTypes::MARTIANA)
56
+ if (hour < 0) || (hour > 24)
57
+ raise ArgumentError, 'Invalid hour'
58
+ end
59
+ if (minute < 0) || (minute > 60)
60
+ raise ArgumentError, 'Invalid minute'
61
+ end
62
+ if (second < 0) || (second > 60)
63
+ raise ArgumentError, 'Invalid second'
64
+ end
65
+
66
+ date = DarianCalendar::Date.by_digits(year, month, sol)
67
+ sols = date.total_sols.to_f
68
+
69
+ second+=1 if (second != 0)
70
+
71
+ sols += (hour.to_f / 24.0)
72
+ sols += (minute.to_f / 1440.0)
73
+ sols += (second.to_f / 86400.0)
74
+
75
+ return self.new(sols, type)
76
+ end
77
+
38
78
  # Compares two times and returns -1, zero, 1 or nil. The other should be a mars time object.
39
79
  # @param another [DarianCalendar::Time]
40
80
  # @return [Integer] Compare result
@@ -59,7 +99,7 @@ module DarianCalendar
59
99
  # Returns the date of the given mars time
60
100
  # @return [DarianCalendar::Date] mars date
61
101
  def to_date
62
- DarianCalendar::Date.new(self.total_sols)
102
+ DarianCalendar::Date.by_digits(self.year, self.month, self.sol, self.calendar_type)
63
103
  end
64
104
 
65
105
  # Converts a number of martian sols to mars time.
@@ -1,3 +1,3 @@
1
1
  module DarianCalendar
2
- VERSION = '1.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -4,6 +4,12 @@ require 'spec_helper'
4
4
 
5
5
  describe DarianCalendar do
6
6
 
7
+ describe 'logical expections' do
8
+ it 'should compare if Date.today and Time.today are equal ' do
9
+ DarianCalendar::Date.today.should == DarianCalendar::Time.today
10
+ end
11
+ end
12
+
7
13
  describe 'class methods' do
8
14
 
9
15
  #def sols_from_earth(earth_date_time)
@@ -12,7 +18,7 @@ describe DarianCalendar do
12
18
  # sols = (days - EPOCH_OFFSET) / MARS_TO_EARTH_DAYS
13
19
  # return sols
14
20
  #end
15
- describe '#sols_from_earth' do
21
+ describe '.sols_from_earth' do
16
22
  context 'parameter is a date object' do
17
23
  it 'returns the total number of martian sols' do
18
24
  earth = ::Date.new(2012, 10, 15)
@@ -27,7 +33,7 @@ describe DarianCalendar do
27
33
  end
28
34
  end
29
35
 
30
- describe '#now' do
36
+ describe '.now' do
31
37
  it 'returns current mars time' do
32
38
  earth = ::Time.utc(2012, 10, 15, 16, 50, 0)
33
39
  ::Time.should_receive(:now).and_return(earth)
@@ -35,13 +41,20 @@ describe DarianCalendar do
35
41
  end
36
42
  end
37
43
 
38
- describe '#today' do
44
+ describe '.today' do
39
45
  it 'returns current mars date' do
40
46
  earth = ::Date.new(2012, 10, 15)
41
47
  ::Date.should_receive(:today).and_return(earth)
42
48
  DarianCalendar.today.should == DarianCalendar::Date.from_earth(earth)
43
49
  end
44
50
  end
51
+
52
+ describe '.is_mars_leap_year?' do
53
+ it 'returns if year is a leap year' do
54
+ DarianCalendar::is_mars_leap_year?(214).should == false
55
+ DarianCalendar::is_mars_leap_year?(215).should == true
56
+ end
57
+ end
45
58
  end
46
59
 
47
60
  end
@@ -6,8 +6,8 @@ describe DarianCalendar::Date do
6
6
 
7
7
  before do
8
8
  @earth_date = ::Date.new(2012, 10, 15)
9
- @mars_date = DarianCalendar::Date.from_earth(@earth_date)
10
- @mars_date_json = '{"calendar_type":"Martiana","month":14,"month_name":"Mithuna","month_of_season":1,"season":2,"sol":26,"sol_of_season":53,"sol_of_year":387,"total_sols":143466.15767923463,"week_sol":5,"week_sol_name":"Sol Jovis","year":214}'
9
+ @mars_date = DarianCalendar::Date.by_digits(214, 14, 26)
10
+ @mars_date_json = '{"calendar_type":"Martiana","month":14,"month_name":"Mithuna","month_of_season":1,"season":2,"sol":26,"sol_of_season":53,"sol_of_year":387,"total_sols":143466,"week_sol":5,"week_sol_name":"Sol Jovis","year":214}'
11
11
  end
12
12
 
13
13
  describe 'attributes' do
@@ -17,25 +17,37 @@ describe DarianCalendar::Date do
17
17
  @mars_date.week_day.should == @mars_date.week_sol
18
18
  end
19
19
 
20
- end
21
-
22
- describe 'initialize method' do
23
- it 'converts earth date to mars date' do
20
+ it 'verifies all attributes' do
24
21
  @mars_date.year.should == 214
25
22
  @mars_date.month.should == 14
26
23
  @mars_date.sol.should == 26
27
24
 
28
- @mars_date.total_sols.should == 143466.15767923463
25
+ @mars_date.total_sols.should == 143466.0
29
26
  @mars_date.season.should == 2
30
27
  @mars_date.sol_of_season.should == 53
31
28
  @mars_date.month_of_season.should == 1
32
29
  @mars_date.sol_of_year.should == 387
33
30
  @mars_date.week_sol.should == 5
34
31
  end
32
+
35
33
  end
36
34
 
37
35
  describe 'class methods' do
38
36
 
37
+ describe '.new' do
38
+ context 'total sols are given' do
39
+ it 'returns mars date by count of martian sols' do
40
+ DarianCalendar::Date.new(@mars_date.total_sols).should == @mars_date
41
+ end
42
+ end
43
+ context 'no sols are given' do
44
+ it 'returns current mars date' do
45
+ ::Date.stub(:today).and_return(@earth_date)
46
+ DarianCalendar::Date.new.should == DarianCalendar::Date.today
47
+ end
48
+ end
49
+ end
50
+
39
51
  describe '.from_earth' do
40
52
  it 'converts an earth date to a mars date' do
41
53
  DarianCalendar::Date.from_earth(@earth_date).should == @mars_date
@@ -50,7 +62,7 @@ describe DarianCalendar::Date do
50
62
 
51
63
  describe '.today' do
52
64
  it 'returns current mars date' do
53
- ::Date.should_receive(:today).and_return(@earth_date)
65
+ ::Date.stub(:today).and_return(@earth_date)
54
66
  DarianCalendar::Date.today.should == DarianCalendar::Date.from_earth(@earth_date)
55
67
  end
56
68
  end
@@ -61,15 +73,63 @@ describe DarianCalendar::Date do
61
73
  end
62
74
  end
63
75
 
76
+ describe '.by_digits' do
77
+ context 'no digits are given' do
78
+ it 'should raise an argument error' do
79
+ expect{DarianCalendar::Date.by_digits}.to raise_error(ArgumentError, 'Invalid year')
80
+ end
81
+ end
82
+ context 'invalid month is given' do
83
+ it 'should raise an argument error' do
84
+ expect{DarianCalendar::Date.by_digits(214, -5)}.to raise_error(ArgumentError, 'Invalid month')
85
+ end
86
+ end
87
+ context 'invalid sol is given' do
88
+ it 'should raise an argument error' do
89
+ expect{DarianCalendar::Date.by_digits(214, 14, 35)}.to raise_error(ArgumentError, 'Invalid sol')
90
+ end
91
+ end
92
+ context 'invalid sol for a month is given' do
93
+ it 'should raise an argument error' do
94
+ expect{DarianCalendar::Date.by_digits(214, 24, 28)}.to raise_error(ArgumentError, 'Invalid sol for this month')
95
+ end
96
+ end
97
+
98
+ context 'only year is given' do
99
+ it 'returns the first of the month 1 of the given year' do
100
+ date = DarianCalendar::Date.by_digits(214)
101
+ date.year.should == 214
102
+ date.month.should == 1
103
+ date.sol.should == 1
104
+ end
105
+ end
106
+ context 'only year and month are given' do
107
+ it 'returns the first of the given month and year' do
108
+ date = DarianCalendar::Date.by_digits(214, 14)
109
+ date.year.should == 214
110
+ date.month.should == 14
111
+ date.sol.should == 1
112
+ end
113
+ end
114
+ context 'all digits are given' do
115
+ it 'returns the date for the given digits' do
116
+ date = DarianCalendar::Date.by_digits(214, 14, 26)
117
+ date.year.should == 214
118
+ date.month.should == 14
119
+ date.sol.should == 26
120
+ end
121
+ end
122
+ end
123
+
64
124
  end
65
125
 
66
126
  describe 'instance methods' do
67
127
 
68
128
  describe '#<=>' do
69
129
  it 'compares mars date objects' do
70
- same_date = DarianCalendar::Date.from_earth(Date.new(2012, 10, 15))
71
- past_date = DarianCalendar::Date.from_earth(Date.new(2012, 10, 14))
72
- future_date = DarianCalendar::Date.from_earth(Date.new(2012, 10, 16))
130
+ same_date = DarianCalendar::Date.by_digits(214, 14, 26)
131
+ past_date = DarianCalendar::Date.by_digits(214, 14, 25)
132
+ future_date = DarianCalendar::Date.by_digits(214, 14, 27)
73
133
 
74
134
  @mars_date.should == same_date
75
135
  @mars_date.should > past_date
@@ -82,7 +142,7 @@ describe DarianCalendar::Date do
82
142
 
83
143
  describe '#sols_in_year' do
84
144
  it 'returns the number of sols in a martian year' do
85
- leap_mars_date = DarianCalendar::Date.from_earth(Date.new(2013, 10, 15))
145
+ leap_mars_date = DarianCalendar::Date.by_digits(215)
86
146
  leap_mars_date.sols_in_year.should == 669
87
147
  @mars_date.sols_in_year.should == 668
88
148
  end
@@ -90,7 +150,7 @@ describe DarianCalendar::Date do
90
150
 
91
151
  describe '#leap?' do
92
152
  it 'returns if year is a leap year' do
93
- leap_mars_date = DarianCalendar::Date.from_earth(Date.new(2013, 10, 15))
153
+ leap_mars_date = DarianCalendar::Date.by_digits(215)
94
154
  leap_mars_date.leap?.should == true
95
155
  @mars_date.leap?.should == false
96
156
  end
@@ -156,6 +216,12 @@ describe DarianCalendar::Date do
156
216
  mars_date.week_sol_name.should == '5'
157
217
  end
158
218
  end
219
+ context 'calendar type is ""' do
220
+ it 'returns ""' do
221
+ mars_date = DarianCalendar::Date.from_earth(@earth_date, :nothing)
222
+ mars_date.week_sol_name.should == ''
223
+ end
224
+ end
159
225
  end
160
226
 
161
227
  describe '#month_name' do
@@ -194,6 +260,12 @@ describe DarianCalendar::Date do
194
260
  mars_date.month_name.should == '14'
195
261
  end
196
262
  end
263
+ context 'calendar type is anything else' do
264
+ it 'returns ""' do
265
+ mars_date = DarianCalendar::Date.from_earth(@earth_date, :nothing)
266
+ mars_date.month_name.should == ''
267
+ end
268
+ end
197
269
  end
198
270
 
199
271
  end
@@ -1,5 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
3
6
  require 'time'
4
7
  require 'date'
5
8
  require 'json'
@@ -19,10 +19,7 @@ describe DarianCalendar::Time do
19
19
  @mars_time.week_day.should == @mars_time.week_sol
20
20
  end
21
21
 
22
- end
23
-
24
- describe 'initialize method' do
25
- it 'converts earth time to mars time' do
22
+ it 'verifies all attributes' do
26
23
  @mars_time.year.should == 214
27
24
  @mars_time.month.should == 14
28
25
  @mars_time.sol.should == 26
@@ -37,6 +34,7 @@ describe DarianCalendar::Time do
37
34
  @mars_time.sol_of_year.should == 387
38
35
  @mars_time.week_sol.should == 5
39
36
  end
37
+
40
38
  end
41
39
 
42
40
  describe 'class methods' do
@@ -55,8 +53,8 @@ describe DarianCalendar::Time do
55
53
 
56
54
  describe '.today' do
57
55
  it 'returns current mars date' do
58
- ::Date.should_receive(:today).and_return(@earth_date)
59
- DarianCalendar::Time.today.should == DarianCalendar::Date.from_earth(@earth_date)
56
+ ::Date.stub(:today).and_return(@earth_date)
57
+ DarianCalendar::Time.today.should == DarianCalendar::Date.by_digits(214, 14, 26)
60
58
  end
61
59
  end
62
60
 
@@ -73,6 +71,114 @@ describe DarianCalendar::Time do
73
71
  end
74
72
  end
75
73
 
74
+ describe '.by_digits' do
75
+ context 'no digits are given' do
76
+ it 'should raise an argument error' do
77
+ expect{DarianCalendar::Time.by_digits}.to raise_error(ArgumentError, 'Invalid year')
78
+ end
79
+ end
80
+ context 'invalid month is given' do
81
+ it 'should raise an argument error' do
82
+ expect{DarianCalendar::Time.by_digits(214, -5)}.to raise_error(ArgumentError, 'Invalid month')
83
+ end
84
+ end
85
+ context 'invalid sol is given' do
86
+ it 'should raise an argument error' do
87
+ expect{DarianCalendar::Time.by_digits(214, 14, 35)}.to raise_error(ArgumentError, 'Invalid sol')
88
+ end
89
+ end
90
+ context 'invalid sol for a month is given' do
91
+ it 'should raise an argument error' do
92
+ expect{DarianCalendar::Time.by_digits(214, 24, 28)}.to raise_error(ArgumentError, 'Invalid sol for this month')
93
+ end
94
+ end
95
+
96
+ context 'invalid hour is given' do
97
+ it 'should raise an argument error' do
98
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 32)}.to raise_error(ArgumentError, 'Invalid hour')
99
+ end
100
+ end
101
+
102
+ context 'invalid minute is given' do
103
+ it 'should raise an argument error' do
104
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 20, 72)}.to raise_error(ArgumentError, 'Invalid minute')
105
+ end
106
+ end
107
+
108
+ context 'invalid second is given' do
109
+ it 'should raise an argument error' do
110
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 20, 10, -18)}.to raise_error(ArgumentError, 'Invalid second')
111
+ end
112
+ end
113
+
114
+ context 'only year is given' do
115
+ it 'returns the first of the month 1 of the given year and 00:00:00' do
116
+ date = DarianCalendar::Time.by_digits(214)
117
+ date.year.should == 214
118
+ date.month.should == 1
119
+ date.sol.should == 1
120
+ date.hour.should == 0
121
+ date.min.should == 0
122
+ date.sec.should == 0
123
+ end
124
+ end
125
+ context 'only year and month are given' do
126
+ it 'returns the first of the given month and year and 00:00:00' do
127
+ date = DarianCalendar::Time.by_digits(214, 14)
128
+ date.year.should == 214
129
+ date.month.should == 14
130
+ date.sol.should == 1
131
+ date.hour.should == 0
132
+ date.min.should == 0
133
+ date.sec.should == 0
134
+ end
135
+ end
136
+ context 'all date but no time digits are given' do
137
+ it 'returns the date for the given digits and 00:00:00' do
138
+ date = DarianCalendar::Time.by_digits(214, 14, 26)
139
+ date.year.should == 214
140
+ date.month.should == 14
141
+ date.sol.should == 26
142
+ date.hour.should == 0
143
+ date.min.should == 0
144
+ date.sec.should == 0
145
+ end
146
+ end
147
+ context 'all date digits and hour are given' do
148
+ it 'returns the date for the given digits and 20:00:00' do
149
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20)
150
+ date.year.should == 214
151
+ date.month.should == 14
152
+ date.sol.should == 26
153
+ date.hour.should == 20
154
+ date.min.should == 0
155
+ date.sec.should == 0
156
+ end
157
+ end
158
+ context 'all date digits, hour and minute are given' do
159
+ it 'returns the date for the given digits and 20:10:00' do
160
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20, 10)
161
+ date.year.should == 214
162
+ date.month.should == 14
163
+ date.sol.should == 26
164
+ date.hour.should == 20
165
+ date.min.should == 10
166
+ date.sec.should == 0
167
+ end
168
+ end
169
+ context 'all digits are given' do
170
+ it 'returns the date for the given digits and 20:10:02' do
171
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20, 10, 2)
172
+ date.year.should == 214
173
+ date.month.should == 14
174
+ date.sol.should == 26
175
+ date.hour.should == 20
176
+ date.min.should == 10
177
+ date.sec.should == 2
178
+ end
179
+ end
180
+ end
181
+
76
182
  end
77
183
 
78
184
  describe 'instance methods' do
@@ -174,6 +280,12 @@ describe DarianCalendar::Time do
174
280
  mars_time.week_sol_name.should == '5'
175
281
  end
176
282
  end
283
+ context 'calendar type is anything else' do
284
+ it 'returns ""' do
285
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, :nothing)
286
+ mars_time.week_sol_name.should == ''
287
+ end
288
+ end
177
289
  end
178
290
 
179
291
  describe '#month_name' do
@@ -212,6 +324,12 @@ describe DarianCalendar::Time do
212
324
  mars_time.month_name.should == '14'
213
325
  end
214
326
  end
327
+ context 'calendar type is anything else' do
328
+ it 'returns ""' do
329
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, :nothing)
330
+ mars_time.month_name.should == ''
331
+ end
332
+ end
215
333
  end
216
334
 
217
335
  end
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: '1.0'
4
+ version: 1.1.0
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-13 00:00:00.000000000 Z
11
+ date: 2014-02-24 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,
@@ -25,6 +25,7 @@ files:
25
25
  - .gitignore
26
26
  - .rspec
27
27
  - .travis.yml
28
+ - .yardopts
28
29
  - CHANGELOG.md
29
30
  - Gemfile
30
31
  - LICENSE.md
@@ -44,7 +45,11 @@ licenses:
44
45
  - EUPL-1.1
45
46
  metadata: {}
46
47
  post_install_message:
47
- rdoc_options: []
48
+ rdoc_options:
49
+ - --line-numbers
50
+ - --inline-source
51
+ - --title
52
+ - Darian Calendar
48
53
  require_paths:
49
54
  - lib
50
55
  required_ruby_version: !ruby/object:Gem::Requirement