darian 0.0.1 → 0.0.2

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.
data/ChangeLog ADDED
@@ -0,0 +1,5 @@
1
+ == 0.0.2 (Mars 6)
2
+ * Add Date class and converter.
3
+
4
+ == 0.0.1 (Mars 3)
5
+ * Initial release
data/README.md CHANGED
@@ -18,7 +18,7 @@ Based on [JS converter] by Thomas Gangale.
18
18
  require 'darian'
19
19
 
20
20
  earth_time = Time.now
21
- mars_time = Darian::Time.from_earth(earth_time)
21
+ mars_time = Darian.from_earth(earth_time)
22
22
 
23
23
  mars_time.to_s #=> "214-09-17 15:07:17"
24
24
 
@@ -29,6 +29,9 @@ mars_time.day #=> 17
29
29
 
30
30
  mars_time.month_name #=> "Aries"
31
31
  mars_time.week_sol_name #=> "Sol Martis"
32
+
33
+ earth_date = Date.today
34
+ mars_date = Darian.from_earth(earth_date)
32
35
  ```
33
36
 
34
37
  ## License
data/lib/darian.rb CHANGED
@@ -20,4 +20,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
  dir = File.join(File.dirname(__FILE__), 'darian')
22
22
  require File.join(dir, 'version')
23
+ require File.join(dir, 'date_methods')
23
24
  require File.join(dir, 'time')
25
+ require File.join(dir, 'date')
26
+
27
+ module Darian
28
+ class << self
29
+
30
+ # Convert `arg` to martian time or date, depend on `arg` class.
31
+ def from_earth(arg)
32
+ if arg.is_a? ::Time
33
+ Darian::Time.from_earth(arg)
34
+ elsif arg.is_a? ::Date
35
+ Darian::Date.from_earth(arg)
36
+ else
37
+ raise ArgumentError, "Can't convert #{arg.class} to martian time or date"
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Darian Mars calendar date converter.
4
+
5
+ Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Lesser General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ module Darian
22
+ # Darian Mars calendar date converter.
23
+ #
24
+ # mars = Darian::Date.from_earth(Date.today)
25
+ # puts mars
26
+ # puts mars.month_name
27
+ class Date
28
+ include DateMethods
29
+
30
+ def self.from_earth(date)
31
+ time = ::Time.parse(date.to_s + " 00:00:00")
32
+ ::Darian::Time.from_earth(time).to_date
33
+ end
34
+
35
+ # Create martian date by time.
36
+ def initialize(time)
37
+ @year = time.year
38
+ @month = time.month
39
+ @sol = time.sol
40
+ @week_sol = time.week_sol
41
+
42
+ @season = time.season
43
+ @sol_of_season = time.sol_of_season
44
+ @month_of_season = time.month_of_season
45
+ end
46
+
47
+ # Printable string of martian date.
48
+ def to_s
49
+ sprintf '%d-%02d-%02d', @year, @month, @sol
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,57 @@
1
+ module Darian
2
+ module DateMethods
3
+ attr_reader :year
4
+ attr_reader :month
5
+ attr_reader :sol
6
+
7
+ attr_reader :week_sol
8
+ attr_reader :season
9
+ attr_reader :sol_of_season
10
+ attr_reader :month_of_season
11
+
12
+ alias :day :sol
13
+ alias :week_day :week_sol
14
+
15
+ def month_name
16
+ case @month
17
+ when 1 then 'Sagittarius'
18
+ when 2 then 'Dhanus'
19
+ when 3 then 'Capricornus'
20
+ when 4 then 'Makara'
21
+ when 5 then 'Aquarius'
22
+ when 6 then 'Kumbha'
23
+ when 7 then 'Pisces'
24
+ when 8 then 'Mina'
25
+ when 9 then 'Aries'
26
+ when 10 then 'Mesha'
27
+ when 11 then 'Taurus'
28
+ when 12 then 'Rishabha'
29
+ when 13 then 'Gemini'
30
+ when 14 then 'Mithuna'
31
+ when 15 then 'Cancer'
32
+ when 16 then 'Karka'
33
+ when 17 then 'Leo'
34
+ when 18 then 'Simha'
35
+ when 19 then 'Virgo'
36
+ when 20 then 'Kanya'
37
+ when 21 then 'Libra'
38
+ when 22 then 'Tula'
39
+ when 23 then 'Scorpius'
40
+ when 24 then 'Vrishika'
41
+ end
42
+ end
43
+
44
+ def week_sol_name
45
+ case @week_sol
46
+ when 1 then 'Sol Solis'
47
+ when 2 then 'Sol Lunae'
48
+ when 3 then 'Sol Martis'
49
+ when 4 then 'Sol Mercurii'
50
+ when 5 then 'Sol Jovis'
51
+ when 6 then 'Sol Veneris'
52
+ when 7 then 'Sol Saturni'
53
+ end
54
+ end
55
+ alias :week_day_name :week_sol_name
56
+ end
57
+ end
data/lib/darian/time.rb CHANGED
@@ -23,28 +23,18 @@ module Darian
23
23
  #
24
24
  # mars = Darian::Time.from_earth(Time.now)
25
25
  # puts mars
26
- # puts mars.sol_name
26
+ # puts mars.month_name
27
27
  class Time
28
28
  MARS_TO_EARTH_DAYS = 1.027491251
29
29
  EPOCH_OFFSET = 587744.77817
30
30
  ROUND_UP_SECOND = 1/86400
31
31
 
32
- attr_reader :year
33
- attr_reader :season
34
- attr_reader :month
35
- attr_reader :month_name
36
- attr_reader :sol
37
- attr_reader :week_sol
32
+ include DateMethods
33
+
38
34
  attr_reader :hour
39
35
  attr_reader :min
40
36
  attr_reader :sec
41
37
 
42
- alias :day :sol
43
- alias :week_day :week_sol
44
-
45
- attr_reader :sol_of_season
46
- attr_reader :month_of_season
47
-
48
38
  # Return Mars time converted from Earth time.
49
39
  #
50
40
  # Darian.from_earth(Time.now)
@@ -123,51 +113,15 @@ module Darian
123
113
  @sec = ((min - min.floor) * 60).floor
124
114
  end
125
115
 
126
- def month_name
127
- case @month
128
- when 1 then 'Sagittarius'
129
- when 2 then 'Dhanus'
130
- when 3 then 'Capricornus'
131
- when 4 then 'Makara'
132
- when 5 then 'Aquarius'
133
- when 6 then 'Kumbha'
134
- when 7 then 'Pisces'
135
- when 8 then 'Mina'
136
- when 9 then 'Aries'
137
- when 10 then 'Mesha'
138
- when 11 then 'Taurus'
139
- when 12 then 'Rishabha'
140
- when 13 then 'Gemini'
141
- when 14 then 'Mithuna'
142
- when 15 then 'Cancer'
143
- when 16 then 'Karka'
144
- when 17 then 'Leo'
145
- when 18 then 'Simha'
146
- when 19 then 'Virgo'
147
- when 20 then 'Kanya'
148
- when 21 then 'Libra'
149
- when 22 then 'Tula'
150
- when 23 then 'Scorpius'
151
- when 24 then 'Vrishika'
152
- end
153
- end
154
-
155
- def week_sol_name
156
- case @week_sol
157
- when 1 then 'Sol Solis'
158
- when 2 then 'Sol Lunae'
159
- when 3 then 'Sol Martis'
160
- when 4 then 'Sol Mercurii'
161
- when 5 then 'Sol Jovis'
162
- when 6 then 'Sol Veneris'
163
- when 7 then 'Sol Saturni'
164
- end
165
- end
166
- alias :week_day_name :week_sol_name
167
-
116
+ # Printable string of martian time.
168
117
  def to_s
169
118
  sprintf '%d-%02d-%02d %02d:%02d:%02d',
170
119
  @year, @month, @sol, @hour, @min, @sec
171
120
  end
121
+
122
+ # Return martian date.
123
+ def to_date
124
+ ::Darian::Date.new(self)
125
+ end
172
126
  end
173
127
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Darian
3
- VERSION = '0.0.1'.freeze unless defined? Darian::VERSION
3
+ VERSION = '0.0.2'.freeze unless defined? Darian::VERSION
4
4
  end
data/spec/darian_spec.rb CHANGED
@@ -7,42 +7,9 @@ describe Darian do
7
7
  Darian::VERSION.should be_a(String)
8
8
  end
9
9
 
10
- describe Darian::Time do
11
- before do
12
- earth = Time.parse('2012-05-16 10:00:00 UTC')
13
- @mars = Darian::Time.from_earth(earth)
14
- end
15
-
16
- it "should convert Earch time to Mars" do
17
- @mars.year.should == 214
18
- @mars.month.should == 9
19
- @mars.sol.should == 17
20
- @mars.hour.should == 15
21
- @mars.min.should == 7
22
- @mars.sec.should == 17
23
-
24
- @mars.week_sol.should == 3
25
-
26
- @mars.season.should == 1
27
- @mars.month_of_season.should == 2
28
- end
29
-
30
- it "should set month name" do
31
- @mars.month_name.should == 'Aries'
32
- end
33
-
34
- it "should set week sol name" do
35
- @mars.week_sol_name.should == 'Sol Martis'
36
- end
37
-
38
- it "should alias day to sol" do
39
- @mars.day.should == @mars.sol
40
- @mars.week_day.should == @mars.week_sol
41
- @mars.week_day_name.should == @mars.week_sol_name
42
- end
43
-
44
- it "should print mars time" do
45
- @mars.to_s.should == '214-09-17 15:07:17'
46
- end
10
+ it "should convert by argument class" do
11
+ Darian.from_earth(Time.now).should be_a(Darian::Time)
12
+ Darian.from_earth(Date.today).should be_a(Darian::Date)
47
13
  end
14
+
48
15
  end
data/spec/date_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../spec_helper', __FILE__)
3
+
4
+ describe Darian::Date do
5
+
6
+ before do
7
+ earth = Date.parse('2012-05-16')
8
+ @mars = Darian::Date.from_earth(earth)
9
+ end
10
+
11
+ it "should convert Earch time to Mars" do
12
+ @mars.year.should == 214
13
+ @mars.month.should == 9
14
+ @mars.sol.should == 17
15
+
16
+ @mars.week_sol.should == 3
17
+
18
+ @mars.season.should == 1
19
+ @mars.month_of_season.should == 2
20
+ end
21
+
22
+ it "should set month and week sol name" do
23
+ @mars.month_name.should == 'Aries'
24
+ @mars.week_sol_name.should == 'Sol Martis'
25
+ end
26
+
27
+ it "should alias day to sol" do
28
+ @mars.day.should == @mars.sol
29
+ @mars.week_day.should == @mars.week_sol
30
+ @mars.week_day_name.should == @mars.week_sol_name
31
+ end
32
+
33
+ it "should print mars time" do
34
+ @mars.to_s.should == '214-09-17'
35
+ end
36
+
37
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'pp'
3
3
  require 'time'
4
+ require 'date'
4
5
 
5
6
  dir = Pathname(__FILE__).dirname
6
7
 
data/spec/time_spec.rb ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../spec_helper', __FILE__)
3
+
4
+ describe Darian::Time do
5
+
6
+ before do
7
+ earth = Time.parse('2012-05-16 10:00:00 UTC')
8
+ @mars = Darian::Time.from_earth(earth)
9
+ end
10
+
11
+ it "should convert Earch time to Mars" do
12
+ @mars.year.should == 214
13
+ @mars.month.should == 9
14
+ @mars.sol.should == 17
15
+ @mars.hour.should == 15
16
+ @mars.min.should == 7
17
+ @mars.sec.should == 17
18
+
19
+ @mars.week_sol.should == 3
20
+
21
+ @mars.season.should == 1
22
+ @mars.month_of_season.should == 2
23
+ end
24
+
25
+ it "should set month and week sol name" do
26
+ @mars.month_name.should == 'Aries'
27
+ @mars.week_sol_name.should == 'Sol Martis'
28
+ end
29
+
30
+ it "should alias day to sol" do
31
+ @mars.day.should == @mars.sol
32
+ @mars.week_day.should == @mars.week_sol
33
+ @mars.week_day_name.should == @mars.week_sol_name
34
+ end
35
+
36
+ it "should print mars time" do
37
+ @mars.to_s.should == '214-09-17 15:07:17'
38
+ end
39
+
40
+ it "should convert to date" do
41
+ date = @mars.to_date
42
+ date.should be_a(Darian::Date)
43
+ date.to_s.should == '214-09-17'
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &13725480 !ruby/object:Gem::Requirement
16
+ requirement: &8318580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.10
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *13725480
24
+ version_requirements: *8318580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &13724980 !ruby/object:Gem::Requirement
27
+ requirement: &8318080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *13724980
35
+ version_requirements: *8318080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &13724500 !ruby/object:Gem::Requirement
38
+ requirement: &8317580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *13724500
46
+ version_requirements: *8317580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &13723960 !ruby/object:Gem::Requirement
49
+ requirement: &8317060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *13723960
57
+ version_requirements: *8317060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: redcarpet
60
- requirement: &13723480 !ruby/object:Gem::Requirement
60
+ requirement: &8316580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *13723480
68
+ version_requirements: *8316580
69
69
  description: ! ' Converter from Earth dates to mars dates by Darian calendar.
70
70
 
71
71
  '
@@ -80,6 +80,7 @@ files:
80
80
  - .rspec
81
81
  - .travis.yml
82
82
  - .yardopts
83
+ - ChangeLog
83
84
  - Gemfile
84
85
  - Gemfile.lock
85
86
  - LICENSE
@@ -87,10 +88,14 @@ files:
87
88
  - Rakefile
88
89
  - darian.gemspec
89
90
  - lib/darian.rb
91
+ - lib/darian/date.rb
92
+ - lib/darian/date_methods.rb
90
93
  - lib/darian/time.rb
91
94
  - lib/darian/version.rb
92
95
  - spec/darian_spec.rb
96
+ - spec/date_spec.rb
93
97
  - spec/spec_helper.rb
98
+ - spec/time_spec.rb
94
99
  homepage: https://github.com/ai/darian
95
100
  licenses: []
96
101
  post_install_message:
@@ -105,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
110
  version: '0'
106
111
  segments:
107
112
  - 0
108
- hash: -4170314655358135603
113
+ hash: 3704348501470939124
109
114
  required_rubygems_version: !ruby/object:Gem::Requirement
110
115
  none: false
111
116
  requirements:
@@ -114,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
119
  version: '0'
115
120
  segments:
116
121
  - 0
117
- hash: -4170314655358135603
122
+ hash: 3704348501470939124
118
123
  requirements: []
119
124
  rubyforge_project:
120
125
  rubygems_version: 1.8.11