era_ja 0.5.3 → 1.0.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
- SHA1:
3
- metadata.gz: 3e6d411b206e4460b298f9aa2d98eb9e94e2fc2e
4
- data.tar.gz: 18fdb71851b63ed43b398bf146df053d46e22f21
2
+ SHA256:
3
+ metadata.gz: 58f5955178ca4a898c771451e6b33345acf59352ae6d89a1fc1334da5b0e2e3a
4
+ data.tar.gz: baef3d1dcc782d26d062095479f6f6121941d2a258e3870dbecbc1080fa3eaba
5
5
  SHA512:
6
- metadata.gz: d1a156a3fcd0d4b379d16fbba05d6516051966a59938cdd8bb05fc2fbc3dc7eb5e9adc466139992b6d17ee793f21e0fa4f9380e1915bb1e42d47ffbf9fb524c0
7
- data.tar.gz: fb3ff1d6ad6c8de4e0d2239dd3e25c1f6c5aa908e6a659183caa003a449422d1b713e1b093d5450947c292d03daf17b7b3bb1bda047ce86e7f39656c493cca8a
6
+ metadata.gz: a501415e87bc28d933553835d1baca333d5c67cd15becf01fca6cbe71ca662cf20e56e427e2bcbfb72dab2650026a1bdd96299ce37ca120614c4028420ac044b
7
+ data.tar.gz: f95522ba00aadfb7f3a97d3eaeb0b7a958f7817e20c3d0a76a618a9b34ef515022223792b794e04c568e8234c2d71607d3d237e7ba79ec203e9ffd91ce1760dd
@@ -2,7 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0-p648
4
4
  - 2.1.10
5
- - 2.2.9
6
- - 2.3.6
7
- - 2.4.3
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.5
9
+ - 2.6.2
8
10
  script: bundle exec rspec spec
@@ -7,7 +7,8 @@ module EraJa
7
7
  meiji: ["M", "明治"],
8
8
  taisho: ["T", "大正"],
9
9
  showa: ["S", "昭和"],
10
- heisei: ["H", "平成"]
10
+ heisei: ["H", "平成"],
11
+ reiwa: ["R", "令和"]
11
12
  }.freeze
12
13
 
13
14
  ERR_DATE_OUT_OF_RANGE = "#to_era only works on dates after 1868,9,8".freeze
@@ -22,7 +23,7 @@ module EraJa
22
23
  # * %J - kanzi number
23
24
  # @param [Hash] era_names
24
25
  # If you want to convert custom to era strings (eg `平`, `h`), you can set this argument.
25
- # key is `:meiji' or `:taisho' or `:showa` or `:heisei`.
26
+ # key is `:meiji' or `:taisho' or `:showa` or `:heisei` or `:reiwa`.
26
27
  # value is ["alphabet era name"(ex `h`, `s`)(related to `%o`), "multibyte era name"(eg `平`, `昭`)(related to `%O`)].
27
28
  # this argument is same as one element of ERA_NAME_DEFAULTS.
28
29
  # @return [String]
@@ -39,8 +40,10 @@ module EraJa
39
40
  str_time = era_year(year - 1911, :taisho, era_names)
40
41
  when self.to_time < ::Time.mktime(1989,1,8)
41
42
  str_time = era_year(year - 1925, :showa, era_names)
42
- else
43
+ when self.to_time < ::Time.mktime(2019, 5, 1)
43
44
  str_time = era_year(year - 1988, :heisei, era_names)
45
+ else
46
+ str_time = era_year(year - 2018, :reiwa, era_names)
44
47
  end
45
48
  end
46
49
  str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
@@ -73,7 +76,7 @@ module EraJa
73
76
  def to_kanzi(numeric, kanzi = "")
74
77
  figures = (10 ** numeric.to_s.size) / 10
75
78
  numeric = numeric.to_i
76
- kanzi_string = [nil, "一", "二", "三", "四", "五", "六", "七", "八", "九"]
79
+ kanzi_string = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"]
77
80
  figures_string = { 1000 => "千", 100 => "百", 10 => "十", 1 => "" }
78
81
  return kanzi + kanzi_string[numeric] if figures == 1
79
82
 
@@ -1,3 +1,3 @@
1
1
  module EraJa
2
- VERSION = "0.5.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -5,6 +5,21 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
5
5
  RSpec.describe Date do
6
6
  describe "#to_era" do
7
7
 
8
+ context "date is 2019,7,2" do
9
+ subject { Date.new(2019,7,2) }
10
+ include_examples "2019,7,2"
11
+ end
12
+
13
+ context 'date is 2019,5,1' do
14
+ subject { Date.new(2019,5,1) }
15
+ include_examples "2019,5,1"
16
+ end
17
+
18
+ context 'date is 2019,4,30' do
19
+ subject { Date.new(2019,4,30) }
20
+ include_examples "2019,4,30"
21
+ end
22
+
8
23
  context "date is 2012,4,29" do
9
24
  subject { Date.new(2012,4,29) }
10
25
  include_examples "2012,4,29"
@@ -1,6 +1,46 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'rspec'
3
3
 
4
+ RSpec.shared_examples "should equal 'R01.07.02'" do
5
+ it { expect(subject.to_era).to eq "R01.07.02" }
6
+
7
+ context "with '%o%E.%m.%d'" do
8
+ it { expect(subject.to_era("%o%E.%m.%d")).to eq "R01.07.02" }
9
+ end
10
+ end
11
+
12
+ RSpec.shared_examples "should equal '令和01年07月02日'" do
13
+ context "with '%O%E年%m月%d日'" do
14
+ it { expect(subject.to_era("%O%E年%m月%d日")).to eq "令和01年07月02日" }
15
+ end
16
+ end
17
+
18
+ RSpec.shared_examples "should equal 'R01.05.01'" do
19
+ it { expect(subject.to_era).to eq "R01.05.01" }
20
+
21
+ context "with '%o%E.%m.%d'" do
22
+ it { expect(subject.to_era("%o%E.%m.%d")).to eq "R01.05.01" }
23
+ end
24
+ end
25
+
26
+ RSpec.shared_examples "should equal '令和01年05月01日'" do
27
+ context "with '%O%E年%m月%d日'" do
28
+ it { expect(subject.to_era("%O%E年%m月%d日")).to eq "令和01年05月01日" }
29
+ end
30
+ end
31
+
32
+ RSpec.shared_examples "should equal '平成三十一年四月三十日'" do
33
+ context "with '%O%JE年%Jm月%Jd日'" do
34
+ it { expect(subject.to_era("%O%JE年%Jm月%Jd日")).to eq "平成三十一年四月三十日" }
35
+ end
36
+ end
37
+
38
+ RSpec.shared_examples "should equal '二千十九年四月三十日'" do
39
+ context "with '%JY年%Jm月%Jd日'" do
40
+ it { expect(subject.to_era("%JY年%Jm月%Jd日")).to eq "二千十九年四月三十日" }
41
+ end
42
+ end
43
+
4
44
  RSpec.shared_examples "should equal 'H24.04.29'" do
5
45
  it { expect(subject.to_era).to eq "H24.04.29" }
6
46
 
@@ -172,6 +212,21 @@ RSpec.shared_examples "should raise error" do
172
212
  it { expect {subject.to_era}.to raise_error(RuntimeError, EraJa::Conversion::ERR_DATE_OUT_OF_RANGE) }
173
213
  end
174
214
 
215
+ RSpec.shared_examples "2019,7,2" do
216
+ include_examples "should equal 'R01.07.02'"
217
+ include_examples "should equal '令和01年07月02日'"
218
+ end
219
+
220
+ RSpec.shared_examples "2019,5,1" do
221
+ include_examples "should equal 'R01.05.01'"
222
+ include_examples "should equal '令和01年05月01日'"
223
+ end
224
+
225
+ RSpec.shared_examples "2019,4,30" do
226
+ include_examples "should equal '平成三十一年四月三十日'"
227
+ include_examples "should equal '二千十九年四月三十日'"
228
+ end
229
+
175
230
  RSpec.shared_examples "2012,4,29" do
176
231
  include_examples "should equal 'H24.04.29'"
177
232
  include_examples "should equal 'h24.04.29'"
@@ -5,6 +5,21 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
5
5
  RSpec.describe Time do
6
6
  describe "#to_era" do
7
7
 
8
+ context 'time is 2019,7,2' do
9
+ subject { Time.mktime(2019,7,2) }
10
+ include_examples "2019,7,2"
11
+ end
12
+
13
+ context 'time is 2019,5,1' do
14
+ subject { Time.mktime(2019,5,1) }
15
+ include_examples "2019,5,1"
16
+ end
17
+
18
+ context 'time is 2019,4,30' do
19
+ subject { Time.mktime(2019,4,30) }
20
+ include_examples "2019,4,30"
21
+ end
22
+
8
23
  context "time is 2012,4,29" do
9
24
  subject { Time.mktime(2012,4,29) }
10
25
  include_examples "2012,4,29"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: era_ja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -139,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.4.5.1
142
+ rubygems_version: 3.0.3
144
143
  signing_key:
145
144
  specification_version: 4
146
145
  summary: Convert Date or Time instance to String of Japanese era.