solar_terms 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/solar_terms/version.rb +3 -0
- data/lib/solar_terms.rb +82 -0
- data/solar_terms.gemspec +17 -0
- data/spec/solar_terms_spec.rb +29 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 xixilive
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# SolarTerms
|
2
|
+
|
3
|
+
Chinese solar terms, extension Date Class, Time Class and DateTime Class.
|
4
|
+
|
5
|
+
"小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'solar_terms'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install solar_terms
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Time.now.solar_term
|
25
|
+
|
26
|
+
Time.now.solar_term_name
|
27
|
+
|
28
|
+
Time.now.solar_term_time
|
29
|
+
|
30
|
+
Date.today.solar_term
|
31
|
+
|
32
|
+
Date.today.solar_term_name
|
33
|
+
|
34
|
+
Date.today.solar_term_time
|
35
|
+
|
36
|
+
Time.new(2012,11,22,5,50,07,"+08:00").solar_term \# return 21
|
37
|
+
|
38
|
+
Time.new(2012,11,22,5,50,07,"+08:00").solar_term_name \# return 小雪
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/solar_terms.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../solar_terms/version', __FILE__)
|
3
|
+
|
4
|
+
module SolarTerms
|
5
|
+
# Timezone: +08:00
|
6
|
+
TERM_NAMES = ["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"]
|
7
|
+
|
8
|
+
TERMS_TABLE = [
|
9
|
+
"2012-01-06 06:43:54","2012-01-21 00:09:49","2012-02-04 18:22:23","2012-02-19 14:17:35","2012-03-05 12:21:02","2012-03-20 13:14:25",
|
10
|
+
"2012-04-04 17:05:36","2012-04-20 00:12:04","2012-05-05 10:19:40","2012-05-20 23:15:31","2012-06-05 14:25:53","2012-06-21 07:08:48",
|
11
|
+
"2012-07-07 00:40:43","2012-07-22 18:00:51","2012-08-07 10:30:32","2012-08-23 01:06:50","2012-09-07 13:29:00","2012-09-22 22:48:59",
|
12
|
+
"2012-10-08 05:11:42","2012-10-23 08:13:33","2012-11-07 08:25:56","2012-11-22 05:50:07","2012-12-07 01:18:55","2012-12-21 19:11:35",
|
13
|
+
|
14
|
+
"2013-01-05 12:33:37","2013-01-20 05:51:42","2013-02-04 00:13:25","2013-02-18 20:01:35","2013-03-05 18:14:51","2013-03-20 19:01:55",
|
15
|
+
"2013-04-04 23:02:27","2013-04-20 06:03:18","2013-05-05 16:18:09","2013-05-21 05:09:30","2013-06-05 20:23:19","2013-06-21 13:03:56",
|
16
|
+
"2013-07-07 06:34:36","2013-07-22 23:55:58","2013-08-07 16:20:21","2013-08-23 07:01:41","2013-09-07 19:16:16","2013-09-23 04:44:08",
|
17
|
+
"2013-10-08 10:58:29","2013-10-23 14:09:48","2013-11-07 14:13:52","2013-11-22 11:48:06","2013-12-07 07:08:31","2013-12-22 01:10:59",
|
18
|
+
|
19
|
+
"2014-01-05 18:24:10","2014-01-20 11:51:14","2014-02-04 06:03:15","2014-02-19 01:59:29","2014-03-06 00:02:15","2014-03-21 00:57:06",
|
20
|
+
"2014-04-05 04:46:39","2014-04-20 11:55:32","2014-05-05 21:59:25","2014-05-21 10:59:02","2014-06-06 02:03:02","2014-06-21 18:51:13",
|
21
|
+
"2014-07-07 12:14:45","2014-07-23 05:41:21","2014-08-07 22:02:28","2014-08-23 12:45:58","2014-09-08 01:01:25","2014-09-23 10:29:04",
|
22
|
+
"2014-10-08 16:47:29","2014-10-23 19:57:03","2014-11-07 20:06:40","2014-11-22 17:38:11","2014-12-07 13:04:05","2014-12-22 07:03:01",
|
23
|
+
|
24
|
+
"2015-01-06 00:20:32","2015-01-20 17:43:14","2015-02-04 11:58:27","2015-02-19 07:49:47","2015-03-06 05:55:39","2015-03-21 06:45:07",
|
25
|
+
"2015-04-05 10:39:07","2015-04-20 17:41:50","2015-05-06 03:52:35","2015-05-21 16:44:45","2015-06-06 07:58:09","2015-06-22 00:37:53",
|
26
|
+
"2015-07-07 18:12:14","2015-07-23 11:30:25","2015-08-08 04:01:23","2015-08-23 18:37:15","2015-09-08 06:59:33","2015-09-23 16:20:31",
|
27
|
+
"2015-10-08 22:42:47","2015-10-24 01:46:41","2015-11-08 01:58:36","2015-11-22 23:25:15","2015-12-07 18:53:19","2015-12-22 12:47:55",
|
28
|
+
|
29
|
+
"2016-01-06 06:08:21","2016-01-20 23:27:04","2016-02-04 17:46:00","2016-02-19 13:33:41","2016-03-05 11:43:30","2016-03-20 12:30:08",
|
30
|
+
"2016-04-04 16:27:29","2016-04-19 23:29:23","2016-05-05 09:41:50","2016-05-20 22:36:26","2016-06-05 13:48:28","2016-06-21 06:34:09",
|
31
|
+
"2016-07-07 00:03:18","2016-07-22 17:30:10","2016-08-07 09:52:58","2016-08-23 00:38:26","2016-09-07 12:51:02","2016-09-22 22:21:05",
|
32
|
+
"2016-10-08 04:33:20","2016-10-23 07:45:30","2016-11-07 07:47:38","2016-11-22 05:22:20","2016-12-07 00:41:05","2016-12-21 18:44:07",
|
33
|
+
|
34
|
+
"2017-01-05 11:55:42","2017-01-20 05:23:33","2017-02-03 23:34:01","2017-02-18 19:31:16","2017-03-05 17:32:40","2017-03-20 18:28:35",
|
35
|
+
"2017-04-04 22:17:16","2017-04-20 05:26:58","2017-05-05 15:30:59","2017-05-21 04:30:53","2017-06-05 19:36:33","2017-06-21 12:24:06",
|
36
|
+
"2017-07-07 05:50:38","2017-07-22 23:15:18","2017-08-07 15:39:58","2017-08-23 06:20:09","2017-09-07 18:38:34","2017-09-23 04:01:44",
|
37
|
+
"2017-10-08 10:22:05","2017-10-23 13:26:36","2017-11-07 13:37:45","2017-11-22 11:04:34","2017-12-07 06:32:35","2017-12-22 00:27:53",
|
38
|
+
|
39
|
+
"2018-01-05 17:48:41","2018-01-20 11:08:58","2018-02-04 05:28:25","2018-02-19 01:17:57","2018-03-05 23:28:06","2018-03-21 00:15:24",
|
40
|
+
"2018-04-05 04:12:43","2018-04-20 11:12:29","2018-05-05 21:25:18","2018-05-21 10:14:33","2018-06-06 01:29:04","2018-06-21 18:07:12",
|
41
|
+
"2018-07-07 11:41:47","2018-07-23 05:00:16","2018-08-07 21:30:34","2018-08-23 12:08:30","2018-09-08 00:29:37","2018-09-23 09:54:01",
|
42
|
+
"2018-10-08 16:14:37","2018-10-23 19:22:18","2018-11-07 19:31:39","2018-11-22 17:01:24","2018-12-07 12:25:48","2018-12-22 06:22:38",
|
43
|
+
|
44
|
+
"2019-01-05 23:38:52","2019-01-20 16:59:27","2019-02-04 11:14:14","2019-02-19 07:03:51","2019-03-06 05:09:39","2019-03-21 05:58:20",
|
45
|
+
"2019-04-05 09:51:21","2019-04-20 16:55:10","2019-05-06 03:02:40","2019-05-21 15:59:01","2019-06-06 07:06:18","2019-06-21 23:54:09",
|
46
|
+
"2019-07-07 17:20:25","2019-07-23 10:50:16","2019-08-08 03:12:57","2019-08-23 18:01:53","2019-09-08 06:16:46","2019-09-23 15:50:02",
|
47
|
+
"2019-10-08 22:05:32","2019-10-24 01:19:37","2019-11-08 01:24:15","2019-11-22 22:58:48","2019-12-07 18:18:21","2019-12-22 12:19:18",
|
48
|
+
|
49
|
+
"2020-01-06 05:29:59","2020-01-20 22:54:33","2020-02-04 17:03:12","2020-02-19 12:56:53","2020-03-05 10:56:44","2020-03-20 11:49:29",
|
50
|
+
"2020-04-04 15:38:02","2020-04-19 22:45:21","2020-05-05 08:51:16","2020-05-20 21:49:09","2020-06-05 12:58:18","2020-06-21 05:43:33",
|
51
|
+
"2020-07-06 23:14:20","2020-07-22 16:36:44","2020-08-07 09:06:03","2020-08-22 23:44:48","2020-09-07 12:07:54","2020-09-22 21:30:32",
|
52
|
+
"2020-10-08 03:55:07","2020-10-23 06:59:25","2020-11-07 07:13:46","2020-11-22 04:39:38","2020-12-07 00:09:21","2020-12-21 19:11:35",
|
53
|
+
"2021-01-05 12:33:37"
|
54
|
+
]
|
55
|
+
|
56
|
+
def solar_term
|
57
|
+
index_of_all_terms % 24
|
58
|
+
end
|
59
|
+
|
60
|
+
def solar_term_name
|
61
|
+
TERM_NAMES[solar_term]
|
62
|
+
end
|
63
|
+
|
64
|
+
def solar_term_time
|
65
|
+
solar_term_times[index_of_all_terms]
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def index_of_all_terms
|
70
|
+
t = self.respond_to?(:to_time) ? self.to_time : self
|
71
|
+
v = solar_term_times.select{|time| time >= t.utc }.first
|
72
|
+
v == t.utc ? solar_term_times.index(v) : solar_term_times.index(v) - 1
|
73
|
+
end
|
74
|
+
|
75
|
+
def solar_term_times
|
76
|
+
@solar_term_times ||= TERMS_TABLE.collect{|s| args = s.split(/[^\d]+/).collect{|n| n.to_i }.push "+08:00"; Time.new(*args).utc }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
Date.class_eval { include ::SolarTerms }
|
81
|
+
Time.class_eval { include ::SolarTerms }
|
82
|
+
DateTime.class_eval { include ::SolarTerms } if defined?(DateTime)
|
data/solar_terms.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/solar_terms/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["xixilive"]
|
6
|
+
gem.email = ["xixilive@gmail.com"]
|
7
|
+
gem.description = %q{Chinese solar terms, mixin Date Class, Time Class and DateTime Class}
|
8
|
+
gem.summary = %q{Chinese solar terms}
|
9
|
+
gem.homepage = "http://github.com/xixilive/solar_terms"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "solar_terms"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SolarTerms::VERSION
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding:utf-8
|
2
|
+
require "solar_terms"
|
3
|
+
require "rspec"
|
4
|
+
|
5
|
+
describe "SolarTerms" do
|
6
|
+
before :each do
|
7
|
+
@current_time = Time.new(2012,11,22,5,50,07,"+08:00")
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'solar_term' do
|
11
|
+
it 'should return the index of current solar term' do
|
12
|
+
@current_time.solar_term.should == 21
|
13
|
+
(@current_time - 1).solar_term.should == 20
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'solar_term_name' do
|
18
|
+
it 'should return the name of current solar term' do
|
19
|
+
@current_time.solar_term_name.should == "小雪"
|
20
|
+
(@current_time - 1).solar_term_name.should == "立冬"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'solar_term_time' do
|
25
|
+
it 'should return a UTC time' do
|
26
|
+
@current_time.solar_term_time.utc?.should be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solar_terms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- xixilive
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Chinese solar terms, mixin Date Class, Time Class and DateTime Class
|
15
|
+
email:
|
16
|
+
- xixilive@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/solar_terms.rb
|
27
|
+
- lib/solar_terms/version.rb
|
28
|
+
- solar_terms.gemspec
|
29
|
+
- spec/solar_terms_spec.rb
|
30
|
+
homepage: http://github.com/xixilive/solar_terms
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Chinese solar terms
|
54
|
+
test_files:
|
55
|
+
- spec/solar_terms_spec.rb
|