solar_terms 0.0.1 → 0.0.3
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/lib/solar_terms.rb +19 -3
- data/lib/solar_terms/version.rb +1 -1
- data/spec/solar_terms_spec.rb +11 -4
- metadata +2 -2
data/lib/solar_terms.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path('../solar_terms/version', __FILE__)
|
3
|
-
|
3
|
+
require 'date'
|
4
4
|
module SolarTerms
|
5
5
|
# Timezone: +08:00
|
6
6
|
TERM_NAMES = ["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"]
|
@@ -65,9 +65,25 @@ module SolarTerms
|
|
65
65
|
solar_term_times[index_of_all_terms]
|
66
66
|
end
|
67
67
|
|
68
|
+
def solar_term_seconds
|
69
|
+
self.to_time.utc.to_i - solar_term_time.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def solar_term_minutes
|
73
|
+
solar_term_seconds / 60.0
|
74
|
+
end
|
75
|
+
|
76
|
+
def solar_term_hours
|
77
|
+
solar_term_seconds / 3600.0
|
78
|
+
end
|
79
|
+
|
80
|
+
def solar_term_days
|
81
|
+
solar_term_seconds / 86400.0
|
82
|
+
end
|
83
|
+
|
68
84
|
private
|
69
85
|
def index_of_all_terms
|
70
|
-
t = self.
|
86
|
+
t = self.to_time
|
71
87
|
v = solar_term_times.select{|time| time >= t.utc }.first
|
72
88
|
v == t.utc ? solar_term_times.index(v) : solar_term_times.index(v) - 1
|
73
89
|
end
|
@@ -79,4 +95,4 @@ end
|
|
79
95
|
|
80
96
|
Date.class_eval { include ::SolarTerms }
|
81
97
|
Time.class_eval { include ::SolarTerms }
|
82
|
-
DateTime.class_eval { include ::SolarTerms }
|
98
|
+
DateTime.class_eval { include ::SolarTerms }
|
data/lib/solar_terms/version.rb
CHANGED
data/spec/solar_terms_spec.rb
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
# encoding:utf-8
|
2
|
-
require
|
2
|
+
require File.expand_path('../../lib/solar_terms', __FILE__)
|
3
3
|
require "rspec"
|
4
4
|
|
5
5
|
describe "SolarTerms" do
|
6
6
|
before :each do
|
7
|
-
@current_time = Time.new(2012,11,22,5,50,
|
7
|
+
@current_time = Time.new(2012,11,22,5,50,9,"+08:00")
|
8
8
|
end
|
9
9
|
|
10
10
|
context 'solar_term' do
|
11
11
|
it 'should return the index of current solar term' do
|
12
12
|
@current_time.solar_term.should == 21
|
13
|
-
(@current_time -
|
13
|
+
(@current_time - 3).solar_term.should == 20
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'solar_term_name' do
|
18
18
|
it 'should return the name of current solar term' do
|
19
19
|
@current_time.solar_term_name.should == "小雪"
|
20
|
-
(@current_time -
|
20
|
+
(@current_time - 3).solar_term_name.should == "立冬"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'solar_term_time' do
|
25
25
|
it 'should return a UTC time' do
|
26
26
|
@current_time.solar_term_time.utc?.should be_true
|
27
|
+
@current_time.solar_term_time.should == @current_time - 2
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "solar_term_seconds" do
|
32
|
+
it "should return seconds from term-begin to current time" do
|
33
|
+
@current_time.solar_term_seconds.should == 2
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solar_terms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Chinese solar terms, mixin Date Class, Time Class and DateTime Class
|
15
15
|
email:
|