darian 0.0.3 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1 (Viking 2)
2
+ * Add Date.today and Time.now shortcuts.
3
+ * Add parse_earth shortcut to Date and Time.
4
+ * Allow to compare dates and times.
5
+
1
6
  == 0.0.3 (Viking 1)
2
7
  * Convert DateTime to martian time.
3
8
  * Fix documentation.
@@ -44,5 +44,15 @@ module Darian
44
44
  end
45
45
  end
46
46
 
47
+ # Return current Mars time. Shortcut for `Darian.from_earth(Time.now)`.
48
+ def now
49
+ Darian::Time.from_earth(::Time.now)
50
+ end
51
+
52
+ # Return current Mars date. Shortcut for `Darian.from_earth(Date.today)`.
53
+ def today
54
+ Darian::Date.from_earth(::Date.today)
55
+ end
56
+
47
57
  end
48
58
  end
@@ -32,12 +32,20 @@ module Darian
32
32
  #
33
33
  # Darian.from_earth(Date.today)
34
34
  def self.from_earth(date)
35
- time = ::Time.parse(date.to_s + " 00:00:00")
35
+ time = ::Time.parse(date.to_s + " 00:00:00 UTC")
36
36
  Darian::Time.from_earth(time).to_date
37
37
  end
38
38
 
39
+ # Parse Earth date and convert to Mars date.
40
+ # Shortcut for `Darian::Date.from_earth(Date.parse(string))`.
41
+ def self.parse_earth(string)
42
+ self.from_earth(::Date.parse(string))
43
+ end
44
+
39
45
  # Create martian date by martian time.
40
46
  def initialize(time)
47
+ @since_epoch = time.since_epoch.floor
48
+
41
49
  @year = time.year
42
50
  @month = time.month
43
51
  @sol = time.sol
@@ -22,10 +22,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22
22
  module Darian
23
23
  # Common date methods for Time and Date classes.
24
24
  module DateMethods
25
+ include Comparable
26
+
25
27
  attr_reader :year
26
28
  attr_reader :month
27
29
  attr_reader :sol
28
30
 
31
+ attr_reader :since_epoch
29
32
  attr_reader :week_sol
30
33
  attr_reader :season
31
34
  attr_reader :sol_of_season
@@ -75,5 +78,9 @@ module Darian
75
78
  end
76
79
  end
77
80
  alias :week_day_name :week_sol_name
81
+
82
+ def <=>(another)
83
+ since_epoch <=> another.since_epoch
84
+ end
78
85
  end
79
86
  end
@@ -46,10 +46,18 @@ module Darian
46
46
  self.new(sols)
47
47
  end
48
48
 
49
+ # Parse Earth time and convert to Mars time.
50
+ # Shortcut for `Darian::Time.from_earth(Time.parse(string))`.
51
+ def self.parse_earth(string)
52
+ self.from_earth(::Time.parse(string))
53
+ end
54
+
49
55
  # Create Mars time by sols since 0 year.
50
56
  #
51
57
  # It is internal contructor. Use `Darian.from_earth`.
52
58
  def initialize(sols)
59
+ @since_epoch = sols
60
+
53
61
  sD = (sols / 334296).floor
54
62
  doD = (sols - (sD * 334296)).floor
55
63
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Darian
3
- VERSION = '0.0.3'.freeze unless defined? Darian::VERSION
3
+ VERSION = '0.1'.freeze unless defined? Darian::VERSION
4
4
  end
@@ -14,4 +14,18 @@ describe Darian do
14
14
  lambda { Darian.from_earth(1) }.should raise_error(ArgumentError)
15
15
  end
16
16
 
17
+ it "should return current time" do
18
+ earth = Time.parse('2012-05-16 10:00:00 UTC')
19
+ Time.should_receive(:now).and_return(earth)
20
+
21
+ Darian.now.should == Darian::Time.from_earth(earth)
22
+ end
23
+
24
+ it "should return current date" do
25
+ earth = Date.parse('2012-05-16')
26
+ Date.should_receive(:today).and_return(earth)
27
+
28
+ Darian.today.should == Darian::Date.from_earth(earth)
29
+ end
30
+
17
31
  end
@@ -8,12 +8,13 @@ describe Darian::Date do
8
8
  @mars = Darian::Date.from_earth(earth)
9
9
  end
10
10
 
11
- it "should convert Earch time to Mars" do
11
+ it "should convert Earth time to Mars" do
12
12
  @mars.year.should == 214
13
13
  @mars.month.should == 9
14
14
  @mars.sol.should == 17
15
15
 
16
- @mars.week_sol.should == 3
16
+ @mars.since_epoch.should == 143318
17
+ @mars.week_sol.should == 3
17
18
 
18
19
  @mars.season.should == 1
19
20
  @mars.month_of_season.should == 2
@@ -25,8 +26,8 @@ describe Darian::Date do
25
26
  end
26
27
 
27
28
  it "should alias day to sol" do
28
- @mars.day.should == @mars.sol
29
- @mars.week_day.should == @mars.week_sol
29
+ @mars.day.should == @mars.sol
30
+ @mars.week_day.should == @mars.week_sol
30
31
  @mars.week_day_name.should == @mars.week_sol_name
31
32
  end
32
33
 
@@ -34,4 +35,21 @@ describe Darian::Date do
34
35
  @mars.to_s.should == '214-09-17'
35
36
  end
36
37
 
38
+ it "should parse Earth date" do
39
+ Darian::Date.parse_earth('2012-05-16').should == @mars
40
+ end
41
+
42
+ it "should compare dates" do
43
+ past = Darian::Date.parse_earth('2012-05-15')
44
+ same = Darian::Date.parse_earth('2012-05-16')
45
+ future = Darian::Date.parse_earth('2012-05-17')
46
+
47
+ @mars.should > past
48
+ @mars.should < future
49
+ @mars.should == same
50
+
51
+ @mars.should_not < past
52
+ @mars.should_not > future
53
+ end
54
+
37
55
  end
@@ -8,7 +8,7 @@ describe Darian::Time do
8
8
  @mars = Darian::Time.from_earth(earth)
9
9
  end
10
10
 
11
- it "should convert Earch time to Mars" do
11
+ it "should convert Earth time to Mars" do
12
12
  @mars.year.should == 214
13
13
  @mars.month.should == 9
14
14
  @mars.sol.should == 17
@@ -16,7 +16,8 @@ describe Darian::Time do
16
16
  @mars.min.should == 7
17
17
  @mars.sec.should == 17
18
18
 
19
- @mars.week_sol.should == 3
19
+ @mars.since_epoch.should == 143318.630064585
20
+ @mars.week_sol.should == 3
20
21
 
21
22
  @mars.season.should == 1
22
23
  @mars.month_of_season.should == 2
@@ -28,8 +29,8 @@ describe Darian::Time do
28
29
  end
29
30
 
30
31
  it "should alias day to sol" do
31
- @mars.day.should == @mars.sol
32
- @mars.week_day.should == @mars.week_sol
32
+ @mars.day.should == @mars.sol
33
+ @mars.week_day.should == @mars.week_sol
33
34
  @mars.week_day_name.should == @mars.week_sol_name
34
35
  end
35
36
 
@@ -43,4 +44,22 @@ describe Darian::Time do
43
44
  date.to_s.should == '214-09-17'
44
45
  end
45
46
 
47
+ it "should parse Earth time" do
48
+ str = '2012-05-16 10:00:00 UTC'
49
+ Darian::Time.parse_earth(str).should == @mars
50
+ end
51
+
52
+ it "should compare times" do
53
+ past = Darian::Time.parse_earth('2012-05-16 09:59:59 UTC')
54
+ same = Darian::Time.parse_earth('2012-05-16 10:00:00 UTC')
55
+ future = Darian::Time.parse_earth('2012-05-16 10:00:01 UTC')
56
+
57
+ @mars.should > past
58
+ @mars.should < future
59
+ @mars.should == same
60
+
61
+ @mars.should_not < past
62
+ @mars.should_not > future
63
+ end
64
+
46
65
  end
metadata CHANGED
@@ -1,17 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
4
  prerelease:
5
+ version: '0.1'
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrey "A.I." Sitnik
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000 Z
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
+ type: :development
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.10
22
+ prerelease: false
15
23
  name: bundler
16
24
  requirement: !ruby/object:Gem::Requirement
17
25
  none: false
@@ -19,15 +27,15 @@ dependencies:
19
27
  - - ! '>='
20
28
  - !ruby/object:Gem::Version
21
29
  version: 1.0.10
30
+ - !ruby/object:Gem::Dependency
22
31
  type: :development
23
- prerelease: false
24
32
  version_requirements: !ruby/object:Gem::Requirement
25
33
  none: false
26
34
  requirements:
27
35
  - - ! '>='
28
36
  - !ruby/object:Gem::Version
29
- version: 1.0.10
30
- - !ruby/object:Gem::Dependency
37
+ version: '0'
38
+ prerelease: false
31
39
  name: yard
32
40
  requirement: !ruby/object:Gem::Requirement
33
41
  none: false
@@ -35,15 +43,15 @@ dependencies:
35
43
  - - ! '>='
36
44
  - !ruby/object:Gem::Version
37
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
38
47
  type: :development
39
- prerelease: false
40
48
  version_requirements: !ruby/object:Gem::Requirement
41
49
  none: false
42
50
  requirements:
43
51
  - - ! '>='
44
52
  - !ruby/object:Gem::Version
45
53
  version: '0'
46
- - !ruby/object:Gem::Dependency
54
+ prerelease: false
47
55
  name: rake
48
56
  requirement: !ruby/object:Gem::Requirement
49
57
  none: false
@@ -51,15 +59,15 @@ dependencies:
51
59
  - - ! '>='
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
54
63
  type: :development
55
- prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
65
  none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
- - !ruby/object:Gem::Dependency
70
+ prerelease: false
63
71
  name: rspec
64
72
  requirement: !ruby/object:Gem::Requirement
65
73
  none: false
@@ -67,15 +75,15 @@ dependencies:
67
75
  - - ! '>='
68
76
  - !ruby/object:Gem::Version
69
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
70
79
  type: :development
71
- prerelease: false
72
80
  version_requirements: !ruby/object:Gem::Requirement
73
81
  none: false
74
82
  requirements:
75
83
  - - ! '>='
76
84
  - !ruby/object:Gem::Version
77
85
  version: '0'
78
- - !ruby/object:Gem::Dependency
86
+ prerelease: false
79
87
  name: redcarpet
80
88
  requirement: !ruby/object:Gem::Requirement
81
89
  none: false
@@ -83,14 +91,6 @@ dependencies:
83
91
  - - ! '>='
84
92
  - !ruby/object:Gem::Version
85
93
  version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
94
  description: ! " This is Ruby library to convert Earth time to Mars time in Darian
95
95
  calendar.\n It use 2002 version of calendar with Telescopic Epoch.\n"
96
96
  email: andrey@sitnik.ru
@@ -132,19 +132,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - ! '>='
134
134
  - !ruby/object:Gem::Version
135
- version: '0'
136
135
  segments:
137
136
  - 0
138
- hash: 856161155010593318
137
+ hash: 3911094043376791761
138
+ version: '0'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements:
142
142
  - - ! '>='
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
145
144
  segments:
146
145
  - 0
147
- hash: 856161155010593318
146
+ hash: 3911094043376791761
147
+ version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
150
  rubygems_version: 1.8.23