wareki 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b36739d46cbd6fd70410c22e27494c22d4bb895
4
- data.tar.gz: cff175bc8ba633cb0521eb0d2e330be0f7568c09
3
+ metadata.gz: e17edc37b9e9bab6955fa886a4b2150927d75e1c
4
+ data.tar.gz: cf48656bd64cbbf26a3d541af8f553e649d4757e
5
5
  SHA512:
6
- metadata.gz: d388a21610e1f9be78807c87898d4c9b6df93302f6d8b97a7590e35b81903d2c6a69dde21aacead7d3384622f8c84cdd55ddd96cad850c6a8fe7e2ffde2075ed
7
- data.tar.gz: 3091f85bde645d4d34ba827bd8e94e3bf4e332dbdf265c9ab6702414746a283e029bc06c4e75da871b37fa82373b5fb0506e278af9f5b2f23c34c0300acc769a
6
+ metadata.gz: 4b437da1a431d1059d5ff1a4f849e999613cb06ca94c0b6d47d86350cf7e18abc30bc993605a41432ab3f64c50a606406ee3c69dd484ee7f0d440372cb26efb5
7
+ data.tar.gz: 3cfc6b10e3906c358d57c19bf179f440df2b18c2365989f7b80d66637c628875fa16cc441d53dcbea9a582855b0e5ce93582d0b379397502a5d00930a65b21ff
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ 2017-07-25 Tatsuki Sugiura <sugi@nemui.org>
2
+
3
+ * Version: 0.2.0
4
+ * Support date calculation (limited with Number)
5
+ * Add compare methods
6
+ * Fix error with "晦日" after Date::GREGORIAN
7
+
1
8
  2017-06-01 Tatsuki Sugiura <sugi@nemui.org>
2
9
 
3
10
  * Version: 0.1.4
@@ -3,11 +3,14 @@ require 'date'
3
3
  require 'wareki/common'
4
4
  require 'wareki/utils'
5
5
  module Wareki
6
-
7
6
  class Date
8
7
  attr_reader :jd
9
8
  attr_accessor :year, :month, :day, :era_year, :era_name
10
9
 
10
+ def self.today
11
+ jd(::Date.today.jd)
12
+ end
13
+
11
14
  def self._parse(str)
12
15
  match = REGEX.match(str.to_s.gsub(/[[:space:]]/, ''))
13
16
  if !match || !match[:year]
@@ -144,6 +147,10 @@ module Wareki
144
147
  ::Date.jd(jd, start)
145
148
  end
146
149
 
150
+ def to_time
151
+ to_date.to_time
152
+ end
153
+
147
154
  def strftime(format_str = "%JF")
148
155
  ret = format_str.to_str.gsub(/%J([fFyYegGoOiImMsSlLdD][kK]?)/) { format($1) || $& }
149
156
  ret.index("%") or return ret
@@ -204,5 +211,46 @@ module Wareki
204
211
  nil
205
212
  end
206
213
  end
214
+
215
+ def eql?(other)
216
+ begin
217
+ [:year, :month, :day, :era_year, :era_name, :leap_month?].each do |attr|
218
+ other.public_send(attr) == public_send(attr) or return false
219
+ end
220
+ rescue => e
221
+ return false
222
+ end
223
+ true
224
+ end
225
+ alias_method :==, :eql?
226
+
227
+ def ===(other)
228
+ begin
229
+ other.jd == jd or return false
230
+ rescue => e
231
+ return false
232
+ end
233
+ true
234
+ end
235
+
236
+ def -(other)
237
+ if other.class.to_s == "ActiveSupport::Duration"
238
+ raise NotImplementedError, "Date calcration with ActiveSupport::Duration currently is not supported. Please use numeric."
239
+ else
240
+ other.respond_to?(:to_date) and other = other.to_date
241
+ other.respond_to?(:jd) and other = other.jd
242
+ self.class.jd jd - other
243
+ end
244
+ end
245
+
246
+ def +(other)
247
+ if other.class.to_s == "ActiveSupport::Duration"
248
+ raise NotImplementedError, "Date calcration with ActiveSupport::Duration currently is not supported. Please use numeric."
249
+ else
250
+ other.respond_to?(:to_date) and other = other.to_date
251
+ other.respond_to?(:jd) and other = other.jd
252
+ self.class.jd jd + other
253
+ end
254
+ end
207
255
  end
208
256
  end
@@ -101,7 +101,7 @@ module Wareki
101
101
  else
102
102
  tmp_m += 1
103
103
  end
104
- day = (::Date.new(tmp_y, tmp_m, 1, Date::GREGORIAN)-1).day
104
+ day = (::Date.new(tmp_y, tmp_m, 1, ::Date::GREGORIAN)-1).day
105
105
  else
106
106
  yobj = YEAR_BY_NUM[year] or
107
107
  raise UnsupportedDateRange, "Cannot find year #{self.inspect}"
@@ -1,3 +1,3 @@
1
1
  module Wareki
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wareki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuki Sugiura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler