ruby_lunardate 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.
- checksums.yaml +7 -0
- data/lib/ruby_lunardate.rb +241 -0
- data/test/test_ruby_lunardate.rb +79 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0eb6210a472bfef08efb25eee58225125e17b832
|
|
4
|
+
data.tar.gz: ca2ac33c7fd4d5c953c8f943481525b5abf1c096
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1e515077eee621ed798eb50941ac01397bd15070eec89c011576bc4d0e48c550f12544d4196c950f915df4d5fd33133bed96124a6bb0bd9800784a428803292d
|
|
7
|
+
data.tar.gz: 438eab88b729ea711632a6c05c684f1ae1becccf494523234dadf3d487ba289413c708c6caac7e0286374ca514805c50ce28770b0aa1553c3bc7f88dc43a766b
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
KOREAN_LUNAR_YEAR_INFO = [
|
|
4
|
+
[384, 1, 2, 1, 1, 2, 1, 2, 4, 2, 2, 1, 2],
|
|
5
|
+
[354, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1],
|
|
6
|
+
[355, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2],
|
|
7
|
+
[383, 1, 2, 1, 2, 3, 2, 1, 1, 2, 2, 1, 2],
|
|
8
|
+
[354, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1],
|
|
9
|
+
[355, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 1, 2],
|
|
10
|
+
[384, 1, 2, 2, 5, 1, 2, 1, 2, 1, 2, 1, 2],
|
|
11
|
+
[354, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1],
|
|
12
|
+
[355, 2, 1, 1, 2, 2, 1, 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|
115
|
+
[354, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 1],
|
|
116
|
+
[384, 2, 1, 6, 2, 1, 2, 1, 1, 2, 1, 2, 1],
|
|
117
|
+
[355, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2],
|
|
118
|
+
[384, 1, 2, 1, 2, 1, 2, 1, 2, 4, 2, 1, 2],
|
|
119
|
+
[354, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1],
|
|
120
|
+
[355, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2],
|
|
121
|
+
[384, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 2, 2],
|
|
122
|
+
[354, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2],
|
|
123
|
+
[354, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2],
|
|
124
|
+
[384, 2, 1, 2, 4, 2, 1, 1, 2, 1, 2, 1, 2],
|
|
125
|
+
[354, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1],
|
|
126
|
+
[355, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2],
|
|
127
|
+
[384, 1, 4, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2],
|
|
128
|
+
[354, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1],
|
|
129
|
+
[384, 2, 1, 2, 1, 1, 4, 2, 1, 2, 2, 2, 1],
|
|
130
|
+
[355, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2],
|
|
131
|
+
[354, 1, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 2],
|
|
132
|
+
[383, 1, 2, 2, 1, 4, 1, 2, 1, 1, 2, 2, 1],
|
|
133
|
+
[355, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2],
|
|
134
|
+
[354, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1],
|
|
135
|
+
[384, 2, 1, 4, 2, 1, 2, 2, 1, 2, 1, 2, 1],
|
|
136
|
+
[355, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2],
|
|
137
|
+
[384, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 4, 2],
|
|
138
|
+
[354, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1],
|
|
139
|
+
[354, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2],
|
|
140
|
+
[384, 2, 2, 1, 2, 1, 5, 1, 1, 2, 2, 1, 2],
|
|
141
|
+
[354, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2],
|
|
142
|
+
[354, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1],
|
|
143
|
+
[384, 2, 2, 1, 2, 4, 2, 1, 2, 1, 2, 1, 1],
|
|
144
|
+
[355, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 1],
|
|
145
|
+
[355, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2],
|
|
146
|
+
[384, 1, 4, 1, 2, 1, 2, 1, 2, 2, 2, 1, 2],
|
|
147
|
+
[354, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2],
|
|
148
|
+
[384, 2, 1, 2, 1, 1, 2, 3, 2, 1, 2, 2, 2],
|
|
149
|
+
[354, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2],
|
|
150
|
+
[354, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2],
|
|
151
|
+
[384, 2, 1, 2, 2, 5, 1, 2, 1, 1, 2, 1, 2],
|
|
152
|
+
[354, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1],
|
|
153
|
+
[355, 2, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1]
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
MAX_YEAR_NUMBER = 150
|
|
157
|
+
CALENDAR_YEAR_INFO_MAP = {
|
|
158
|
+
ko: KOREAN_LUNAR_YEAR_INFO
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
LUNARDAYS_FOR_MONTHTYPE = {
|
|
162
|
+
1 => [29, 29, 0],
|
|
163
|
+
2 => [30, 30, 0],
|
|
164
|
+
3 => [58, 29, 29],
|
|
165
|
+
4 => [59, 30, 29],
|
|
166
|
+
5 => [59, 29, 30],
|
|
167
|
+
6 => [60, 30, 30]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
class LunarDate
|
|
171
|
+
attr_accessor :year, :month, :day, :is_leap_month
|
|
172
|
+
|
|
173
|
+
@start_date = Date.new(1900,1,31)
|
|
174
|
+
@calendar_symbol = :ko
|
|
175
|
+
|
|
176
|
+
def initialize(year, month, day, is_leap_month = false)
|
|
177
|
+
self.year = year
|
|
178
|
+
self.month = month
|
|
179
|
+
self.day = day
|
|
180
|
+
self.is_leap_month = is_leap_month
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def self.lunardays_for_type(month_type)
|
|
184
|
+
return LUNARDAYS_FOR_MONTHTYPE[month_type]
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def self.year_info_map
|
|
188
|
+
return CALENDAR_YEAR_INFO_MAP[@calendar_symbol]
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def self.to_lunar(year, month, day, locale = :ko)
|
|
192
|
+
solar_date = Date.new(year, month, day)
|
|
193
|
+
days = (solar_date - @start_date).to_i
|
|
194
|
+
# @calendar_symbol = locale
|
|
195
|
+
return self.from_days(days)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def self.is_in_this_days(days, left_days)
|
|
199
|
+
return (days - left_days) < 0
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def self.is_not_in_this_days(days, left_days)
|
|
203
|
+
return self.is_in_this_days(days, left_days) == false
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def self.from_days(days)
|
|
207
|
+
start_year = 1900
|
|
208
|
+
target_month = 0
|
|
209
|
+
is_leap_month = false
|
|
210
|
+
matched = false
|
|
211
|
+
year_info = self.year_info_map
|
|
212
|
+
|
|
213
|
+
MAX_YEAR_NUMBER.times do |year_idx|
|
|
214
|
+
year_days = year_info[year_idx][0]
|
|
215
|
+
if self.is_in_this_days(days, year_days)
|
|
216
|
+
12.times do |month_idx|
|
|
217
|
+
total, normal, leap = self.lunardays_for_type(year_info[year_idx][month_idx+1])
|
|
218
|
+
if self.is_in_this_days(days, total)
|
|
219
|
+
if self.is_not_in_this_days(days, normal)
|
|
220
|
+
days -= normal
|
|
221
|
+
is_leap_month = true
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
matched = true
|
|
225
|
+
break
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
days -= total
|
|
229
|
+
target_month += 1
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
break if matched
|
|
234
|
+
|
|
235
|
+
days -= year_days
|
|
236
|
+
start_year += 1
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
return self.new(start_year, target_month + 1, days + 1, is_leap_month)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'ruby_lunardate'
|
|
3
|
+
|
|
4
|
+
class TestRubyLunarDate < Minitest::Test
|
|
5
|
+
def test_to_lunar_19790922_from_solar_19791111
|
|
6
|
+
date = LunarDate.to_lunar(1979, 11, 11)
|
|
7
|
+
assert_equal(date.year, 1979)
|
|
8
|
+
assert_equal(date.month, 9)
|
|
9
|
+
assert_equal(date.day, 22)
|
|
10
|
+
assert_equal(date.is_leap_month, false)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_to_lunar_19000101_from_solar_19000131
|
|
14
|
+
date = LunarDate.to_lunar(1900, 1, 31)
|
|
15
|
+
assert_equal(date.year, 1900)
|
|
16
|
+
assert_equal(date.month, 1)
|
|
17
|
+
assert_equal(date.day, 1)
|
|
18
|
+
assert_equal(date.is_leap_month, false)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_to_lunar_19020101_from_solar_19020208
|
|
22
|
+
date = LunarDate.to_lunar(1902, 2, 8)
|
|
23
|
+
assert_equal(date.year, 1902)
|
|
24
|
+
assert_equal(date.month, 1)
|
|
25
|
+
assert_equal(date.day, 1)
|
|
26
|
+
assert_equal(date.is_leap_month, false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_to_lunar_19040101_from_solar_19040216
|
|
30
|
+
date = LunarDate.to_lunar(1904, 2, 16)
|
|
31
|
+
assert_equal(date.year, 1904)
|
|
32
|
+
assert_equal(date.month, 1)
|
|
33
|
+
assert_equal(date.day, 1)
|
|
34
|
+
assert_equal(date.is_leap_month, false)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_to_lunar_20140930_from_solar_20141023
|
|
38
|
+
date = LunarDate.to_lunar(2014, 10, 23)
|
|
39
|
+
assert_equal(date.year, 2014)
|
|
40
|
+
assert_equal(date.month, 9)
|
|
41
|
+
assert_equal(date.day, 30)
|
|
42
|
+
assert_equal(date.is_leap_month, false)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_to_lunar_19870621_from_solar_19870815_leap
|
|
46
|
+
date = LunarDate.to_lunar(1987, 8, 15)
|
|
47
|
+
assert_equal(date.year, 1987)
|
|
48
|
+
assert_equal(date.month, 6)
|
|
49
|
+
assert_equal(date.day, 21)
|
|
50
|
+
assert_equal(date.is_leap_month, true)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# 3rd MONTHTYPE test case
|
|
54
|
+
def test_to_lunar_20171025_from_solar_20171212
|
|
55
|
+
date = LunarDate.to_lunar(2017, 12, 12)
|
|
56
|
+
assert_equal(date.year, 2017)
|
|
57
|
+
assert_equal(date.month, 10)
|
|
58
|
+
assert_equal(date.day, 25)
|
|
59
|
+
assert_equal(date.is_leap_month, false)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# 4th MONTHTYPE test case
|
|
63
|
+
def test_to_lunar_19870729_from_solar_19870921
|
|
64
|
+
date = LunarDate.to_lunar(1987, 9, 21)
|
|
65
|
+
assert_equal(date.year, 1987)
|
|
66
|
+
assert_equal(date.month, 7)
|
|
67
|
+
assert_equal(date.day, 29)
|
|
68
|
+
assert_equal(date.is_leap_month, false)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# 5th MONTHTYPE test case
|
|
72
|
+
def test_to_lunar_19551119_from_solar_19560101
|
|
73
|
+
date = LunarDate.to_lunar(1956, 1, 1)
|
|
74
|
+
assert_equal(date.year, 1955)
|
|
75
|
+
assert_equal(date.month, 11)
|
|
76
|
+
assert_equal(date.day, 19)
|
|
77
|
+
assert_equal(date.is_leap_month, false)
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby_lunardate
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- sunsidew
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Korean Lunar Calendar Library
|
|
14
|
+
email: sunsidew.yjw@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/ruby_lunardate.rb
|
|
20
|
+
- test/test_ruby_lunardate.rb
|
|
21
|
+
homepage: https://github.com/sunsidew/ruby_lunardate
|
|
22
|
+
licenses:
|
|
23
|
+
- BSD
|
|
24
|
+
metadata:
|
|
25
|
+
allowed_push_host: https://rubygems.org
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.4.6
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Korean Lunar Calendar Library
|
|
46
|
+
test_files:
|
|
47
|
+
- test/test_ruby_lunardate.rb
|
|
48
|
+
has_rdoc:
|