ruby_lunardate 0.0.7 → 0.1.0
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 +4 -4
- data/lib/ruby_lunardate.rb +14 -19
- data/test/test_ruby_lunardate.rb +12 -12
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e27df958bc842fd3b234da92b3f17650d513bc23
|
|
4
|
+
data.tar.gz: aacff5f2856b9b928b1669708bc713394bb02c1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba4bc961dc82040eba279cd62ee02abfa710c078f130c729cf5f9e9385382ec8eb2138ade7fde0df1f43e94794cc7243318b1f96e427763ec5fe7203fa26d7aa
|
|
7
|
+
data.tar.gz: d42a36287e5ca14dab5976c779435d209952140a84bc0fb0a22e4cc11c9a247e05fdc2e118b6faae87be17dad06f5906d33473cb6cf1e8175d3b242e62e5acb1
|
data/lib/ruby_lunardate.rb
CHANGED
|
@@ -168,13 +168,12 @@ LUNARDAYS_FOR_MONTHTYPE = {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
class Date
|
|
171
|
-
def
|
|
172
|
-
|
|
173
|
-
return LunarDate.lunar_from_days(days, self.class)
|
|
171
|
+
def from_solar
|
|
172
|
+
return LunarDate.from_solar(self.year, self.month, self.day)
|
|
174
173
|
end
|
|
175
174
|
|
|
176
175
|
def to_solar(is_leap_month = false)
|
|
177
|
-
return LunarDate.to_solar(self.year, self.month, self.day, is_leap_month
|
|
176
|
+
return LunarDate.to_solar(self.year, self.month, self.day, is_leap_month)
|
|
178
177
|
end
|
|
179
178
|
end
|
|
180
179
|
|
|
@@ -207,14 +206,14 @@ class LunarDate
|
|
|
207
206
|
return CALENDAR_YEAR_INFO_MAP[@calendar_symbol]
|
|
208
207
|
end
|
|
209
208
|
|
|
210
|
-
def self.
|
|
211
|
-
|
|
209
|
+
def self.get_days(solar_date)
|
|
210
|
+
return (solar_date - @start_date).to_i
|
|
212
211
|
end
|
|
213
212
|
|
|
214
213
|
def self.from_solar(year, month, day)
|
|
215
214
|
solar_date = Date.new(year, month, day)
|
|
216
|
-
days = self.
|
|
217
|
-
return self.lunar_from_days(days
|
|
215
|
+
days = self.get_days(solar_date)
|
|
216
|
+
return self.lunar_from_days(days)
|
|
218
217
|
end
|
|
219
218
|
|
|
220
219
|
def self.is_in_this_days(days, left_days)
|
|
@@ -225,7 +224,7 @@ class LunarDate
|
|
|
225
224
|
return self.is_in_this_days(days, left_days) == false
|
|
226
225
|
end
|
|
227
226
|
|
|
228
|
-
def self.lunar_from_days(days
|
|
227
|
+
def self.lunar_from_days(days)
|
|
229
228
|
start_year = 1900
|
|
230
229
|
target_month = 0
|
|
231
230
|
is_leap_month = false
|
|
@@ -257,14 +256,13 @@ class LunarDate
|
|
|
257
256
|
days -= year_days
|
|
258
257
|
start_year += 1
|
|
259
258
|
end
|
|
259
|
+
|
|
260
|
+
lunar_date = self.new(start_year, target_month + 1, days + 1, is_leap_month)
|
|
260
261
|
|
|
261
|
-
|
|
262
|
-
target_date.is_leap_month = is_leap_month if type == self
|
|
263
|
-
|
|
264
|
-
return target_date
|
|
262
|
+
return lunar_date
|
|
265
263
|
end
|
|
266
264
|
|
|
267
|
-
def self.to_solar(year, month, day, is_leap_month = false
|
|
265
|
+
def self.to_solar(year, month, day, is_leap_month = false)
|
|
268
266
|
days = 0
|
|
269
267
|
year_diff = year-1900
|
|
270
268
|
year_info = self.year_info_map
|
|
@@ -286,9 +284,6 @@ class LunarDate
|
|
|
286
284
|
|
|
287
285
|
solar_date = @start_date+days
|
|
288
286
|
|
|
289
|
-
|
|
290
|
-
target_date.is_leap_month = is_leap_month if type == self
|
|
291
|
-
|
|
292
|
-
return target_date
|
|
287
|
+
return solar_date
|
|
293
288
|
end
|
|
294
|
-
end
|
|
289
|
+
end
|
data/test/test_ruby_lunardate.rb
CHANGED
|
@@ -146,17 +146,17 @@ class TestRubyLunarDate < Minitest::Test
|
|
|
146
146
|
assert_equal(lunar_date_leap.day, 8)
|
|
147
147
|
end
|
|
148
148
|
|
|
149
|
-
def
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
assert_equal(
|
|
154
|
-
assert_equal(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
assert_equal(
|
|
160
|
-
assert_equal(
|
|
149
|
+
def test_from_lunar_solar_from_Date_class_variable_20150908
|
|
150
|
+
lunar_date = Date.new(2015,9,8).from_solar
|
|
151
|
+
assert_equal(lunar_date.year, 2015)
|
|
152
|
+
assert_equal(lunar_date.month, 7)
|
|
153
|
+
assert_equal(lunar_date.day, 26)
|
|
154
|
+
assert_equal(lunar_date.class, LunarDate)
|
|
155
|
+
|
|
156
|
+
solar_date = Date.new(2015,7,26).to_solar
|
|
157
|
+
assert_equal(solar_date.year, 2015)
|
|
158
|
+
assert_equal(solar_date.month, 9)
|
|
159
|
+
assert_equal(solar_date.day, 8)
|
|
160
|
+
assert_equal(solar_date.class, Date)
|
|
161
161
|
end
|
|
162
162
|
end
|