ruby_lunardate 0.0.4 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19dbabf87671d56ee610e61a84ad364629cbc6ac
4
- data.tar.gz: 74a2287e47276439916d30a4cd6cc36c41eae871
3
+ metadata.gz: d2d4a3f8dd0e16ee050fea3d77bae6e3965a0ce1
4
+ data.tar.gz: 1107f26640819db8d0997fac9fc1541022f5bf4d
5
5
  SHA512:
6
- metadata.gz: 6a68946d3a2d4f7432612eed11af14259ebc22815dafbf8990ccba9f6e0f3cd4cfe59ad5f95e70606dca2eb60c8fdb2fb3a042691a98483ce837bf1323cfaa6b
7
- data.tar.gz: dddae6a001770ca66213abe65f7a5cf0c01f5ee054f5555f8b92a2f264e30a6d2dcc0315ed22bb63d469d42ce28b29950612f4bdc72986cd0f2f0fafc023f1cb
6
+ metadata.gz: d4d678c8d317ad5f2ab42f5da0c852a8da22920c561c808572a0512e9e738e71e45cfbb89cbb6c34de7a92d5c834e15f6d2be7582e3697475eb6a81be73d189d
7
+ data.tar.gz: 983544452b663aa2d8690e5b1c2f65706a497fbe8572aca467f1dbddaabd17aace8596f46a4d2f35e66153e06c33c57b3105ad3e35ad5dc21b80a6e0fc68e68e
@@ -170,7 +170,11 @@ LUNARDAYS_FOR_MONTHTYPE = {
170
170
  class Date
171
171
  def to_lunar
172
172
  days = LunarDate.get_dates(self)
173
- return LunarDate.from_days(days, self.class)
173
+ return LunarDate.lunar_from_days(days, self.class)
174
+ end
175
+
176
+ def to_solar(is_leap_month = false)
177
+ return LunarDate.to_solar(self.year, self.month, self.day, is_leap_month, self.class)
174
178
  end
175
179
  end
176
180
 
@@ -188,7 +192,7 @@ class LunarDate
188
192
  end
189
193
 
190
194
  def to_s
191
- return "%4d%02d%02d" % [self.year,self.month,self.day]
195
+ return "%4d%02d%02d" % [self.year,self.month,self.day]
192
196
  end
193
197
 
194
198
  def inspect
@@ -207,11 +211,10 @@ class LunarDate
207
211
  return (solar_date - @start_date).to_i
208
212
  end
209
213
 
210
- def self.to_lunar(year, month, day, locale = :ko)
214
+ def self.to_lunar(year, month, day)
211
215
  solar_date = Date.new(year, month, day)
212
216
  days = self.get_dates(solar_date)
213
- # @calendar_symbol = locale
214
- return self.from_days(days, self)
217
+ return self.lunar_from_days(days, self)
215
218
  end
216
219
 
217
220
  def self.is_in_this_days(days, left_days)
@@ -222,7 +225,7 @@ class LunarDate
222
225
  return self.is_in_this_days(days, left_days) == false
223
226
  end
224
227
 
225
- def self.from_days(days, type)
228
+ def self.lunar_from_days(days, type)
226
229
  start_year = 1900
227
230
  target_month = 0
228
231
  is_leap_month = false
@@ -260,4 +263,32 @@ class LunarDate
260
263
 
261
264
  return target_date
262
265
  end
266
+
267
+ def self.to_solar(year, month, day, is_leap_month = false, type = self)
268
+ days = 0
269
+ year_diff = year-1900
270
+ year_info = self.year_info_map
271
+
272
+ year_diff.times do |year_idx|
273
+ days += year_info[year_idx][0]
274
+ end
275
+
276
+ (month-1).times do |month_idx|
277
+ total, normal, leap = self.lunardays_for_type(year_info[year_diff][month_idx+1])
278
+ days += total
279
+ end
280
+
281
+ days += (day-1)
282
+
283
+ if is_leap_month && year_info[year_diff][month] > 2
284
+ days += self.lunardays_for_type(year_info[year_diff][month])[1]
285
+ end
286
+
287
+ solar_date = @start_date+days
288
+
289
+ target_date = type.new(solar_date.year, solar_date.month, solar_date.day)
290
+ target_date.is_leap_month = is_leap_month if type == self
291
+
292
+ return target_date
293
+ end
263
294
  end
@@ -8,6 +8,11 @@ class TestRubyLunarDate < Minitest::Test
8
8
  assert_equal(date.month, 9)
9
9
  assert_equal(date.day, 22)
10
10
  assert_equal(date.is_leap_month, false)
11
+
12
+ lunar_date = LunarDate.to_solar(1979, 9, 22, false)
13
+ assert_equal(lunar_date.year, 1979)
14
+ assert_equal(lunar_date.month, 11)
15
+ assert_equal(lunar_date.day, 11)
11
16
  end
12
17
 
13
18
  def test_to_lunar_19000101_from_solar_19000131
@@ -16,6 +21,11 @@ class TestRubyLunarDate < Minitest::Test
16
21
  assert_equal(date.month, 1)
17
22
  assert_equal(date.day, 1)
18
23
  assert_equal(date.is_leap_month, false)
24
+
25
+ lunar_date = LunarDate.to_solar(1900, 1, 1, false)
26
+ assert_equal(lunar_date.year, 1900)
27
+ assert_equal(lunar_date.month, 1)
28
+ assert_equal(lunar_date.day, 31)
19
29
  end
20
30
 
21
31
  def test_to_lunar_19020101_from_solar_19020208
@@ -24,6 +34,11 @@ class TestRubyLunarDate < Minitest::Test
24
34
  assert_equal(date.month, 1)
25
35
  assert_equal(date.day, 1)
26
36
  assert_equal(date.is_leap_month, false)
37
+
38
+ lunar_date = LunarDate.to_solar(1902, 1, 1, false)
39
+ assert_equal(lunar_date.year, 1902)
40
+ assert_equal(lunar_date.month, 2)
41
+ assert_equal(lunar_date.day, 8)
27
42
  end
28
43
 
29
44
  def test_to_lunar_19040101_from_solar_19040216
@@ -32,6 +47,11 @@ class TestRubyLunarDate < Minitest::Test
32
47
  assert_equal(date.month, 1)
33
48
  assert_equal(date.day, 1)
34
49
  assert_equal(date.is_leap_month, false)
50
+
51
+ lunar_date = LunarDate.to_solar(1904, 1, 1, false)
52
+ assert_equal(lunar_date.year, 1904)
53
+ assert_equal(lunar_date.month, 2)
54
+ assert_equal(lunar_date.day, 16)
35
55
  end
36
56
 
37
57
  def test_to_lunar_20140930_from_solar_20141023
@@ -40,6 +60,11 @@ class TestRubyLunarDate < Minitest::Test
40
60
  assert_equal(date.month, 9)
41
61
  assert_equal(date.day, 30)
42
62
  assert_equal(date.is_leap_month, false)
63
+
64
+ lunar_date = LunarDate.to_solar(2014, 9, 30, false)
65
+ assert_equal(lunar_date.year, 2014)
66
+ assert_equal(lunar_date.month, 10)
67
+ assert_equal(lunar_date.day, 23)
43
68
  end
44
69
 
45
70
  def test_to_lunar_19870621_from_solar_19870815_leap
@@ -48,6 +73,11 @@ class TestRubyLunarDate < Minitest::Test
48
73
  assert_equal(date.month, 6)
49
74
  assert_equal(date.day, 21)
50
75
  assert_equal(date.is_leap_month, true)
76
+
77
+ lunar_date = LunarDate.to_solar(1987, 6, 21, true)
78
+ assert_equal(lunar_date.year, 1987)
79
+ assert_equal(lunar_date.month, 8)
80
+ assert_equal(lunar_date.day, 15)
51
81
  end
52
82
 
53
83
  # 3rd MONTHTYPE test case
@@ -57,6 +87,11 @@ class TestRubyLunarDate < Minitest::Test
57
87
  assert_equal(date.month, 10)
58
88
  assert_equal(date.day, 25)
59
89
  assert_equal(date.is_leap_month, false)
90
+
91
+ lunar_date = LunarDate.to_solar(2017, 10, 25, false)
92
+ assert_equal(lunar_date.year, 2017)
93
+ assert_equal(lunar_date.month, 12)
94
+ assert_equal(lunar_date.day, 12)
60
95
  end
61
96
 
62
97
  # 4th MONTHTYPE test case
@@ -66,6 +101,11 @@ class TestRubyLunarDate < Minitest::Test
66
101
  assert_equal(date.month, 7)
67
102
  assert_equal(date.day, 29)
68
103
  assert_equal(date.is_leap_month, false)
104
+
105
+ lunar_date = LunarDate.to_solar(1987, 7, 29, false)
106
+ assert_equal(lunar_date.year, 1987)
107
+ assert_equal(lunar_date.month, 9)
108
+ assert_equal(lunar_date.day, 21)
69
109
  end
70
110
 
71
111
  # 5th MONTHTYPE test case
@@ -75,13 +115,48 @@ class TestRubyLunarDate < Minitest::Test
75
115
  assert_equal(date.month, 11)
76
116
  assert_equal(date.day, 19)
77
117
  assert_equal(date.is_leap_month, false)
118
+
119
+ lunar_date = LunarDate.to_solar(1955, 11, 19, false)
120
+ assert_equal(lunar_date.year, 1956)
121
+ assert_equal(lunar_date.month, 1)
122
+ assert_equal(lunar_date.day, 1)
78
123
  end
79
124
 
80
- def test_to_lunar_from_Date_class_variable_20150908
125
+ def test_solar_from_lunar_19550329_leap_double_case_check
126
+ lunar_date = LunarDate.to_solar(1955, 3, 29, false)
127
+ assert_equal(lunar_date.year, 1955)
128
+ assert_equal(lunar_date.month, 4)
129
+ assert_equal(lunar_date.day, 21)
130
+
131
+ lunar_date_leap = LunarDate.to_solar(1955, 3, 29, true)
132
+ assert_equal(lunar_date_leap.year, 1955)
133
+ assert_equal(lunar_date_leap.month, 5)
134
+ assert_equal(lunar_date_leap.day, 20)
135
+ end
136
+
137
+ def test_solar_from_lunar_20150908_not_leap_month_case_check
138
+ lunar_date = LunarDate.to_solar(2015, 7, 26, false)
139
+ assert_equal(lunar_date.year, 2015)
140
+ assert_equal(lunar_date.month, 9)
141
+ assert_equal(lunar_date.day, 8)
142
+
143
+ lunar_date_leap = LunarDate.to_solar(2015, 7, 26, true)
144
+ assert_equal(lunar_date_leap.year, 2015)
145
+ assert_equal(lunar_date_leap.month, 9)
146
+ assert_equal(lunar_date_leap.day, 8)
147
+ end
148
+
149
+ def test_to_lunar_solar_from_Date_class_variable_20150908
81
150
  date = Date.new(2015,9,8)
82
151
  date = date.to_lunar
83
152
  assert_equal(date.year, 2015)
84
153
  assert_equal(date.month, 7)
85
154
  assert_equal(date.day, 26)
155
+
156
+ date = Date.new(2015,7,26)
157
+ date = date.to_solar
158
+ assert_equal(date.year, 2015)
159
+ assert_equal(date.month, 9)
160
+ assert_equal(date.day, 8)
86
161
  end
87
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_lunardate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sunsidew
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Korean Lunar Calendar Library
13
+ description: 'Korean lunar, solar date two-way convert library '
14
14
  email: sunsidew.yjw@gmail.com
15
15
  executables: []
16
16
  extensions: []
@@ -42,7 +42,7 @@ rubyforge_project:
42
42
  rubygems_version: 2.4.6
43
43
  signing_key:
44
44
  specification_version: 4
45
- summary: Korean Lunar Calendar Library
45
+ summary: Korean Lunar/Solar Calendar Library
46
46
  test_files:
47
47
  - test/test_ruby_lunardate.rb
48
48
  has_rdoc: