era_ja 0.5.3 → 1.2.2
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 +5 -5
- data/.travis.yml +6 -3
- data/README.ja.md +26 -11
- data/README.md +20 -7
- data/era_ja.gemspec +1 -1
- data/lib/era_ja.rb +1 -0
- data/lib/era_ja/conversion.rb +25 -12
- data/lib/era_ja/error.rb +9 -0
- data/lib/era_ja/version.rb +1 -1
- data/spec/date_spec.rb +36 -0
- data/spec/spec_helper.rb +191 -1
- data/spec/time_spec.rb +20 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bcf0a0de20e3f4e090835b70d95bd314e00969368a7d11930d4f138b10a5a479
|
4
|
+
data.tar.gz: 3faa10bd05537ebe7ac6bd279e32576701b8369ad1ac72c8198f9073fe0a1aa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbbb0bf965c38428ba6c63057ab1c49b1dad5912c46480440386e6c5ce01e39185fa4e65b9de8ac990928d818308fb6183b42b1327192ae52b37da7f578a99bf
|
7
|
+
data.tar.gz: d2a6df2467587f964a74d869de4e59cae8da84ca062b3dda6f61074be7420d212c97d4111d697046f7b92a551b2059b90b9a4e29975520e0b37bb5c074b47ec6
|
data/.travis.yml
CHANGED
data/README.ja.md
CHANGED
@@ -26,20 +26,23 @@
|
|
26
26
|
|
27
27
|
### フォーマット文字列
|
28
28
|
|
29
|
-
引数として
|
29
|
+
引数としてstrftimeのフォーマット文字列を使用出来ます。
|
30
30
|
|
31
31
|
EraJa#to_eraメソッドでの追加のフォーマット文字列は以下の通りです。
|
32
32
|
|
33
|
-
* %o:
|
34
|
-
* %O:
|
35
|
-
* %
|
33
|
+
* %o: 元号(アルファベット)
|
34
|
+
* %O: 元号(漢字)
|
35
|
+
* %1O: 元号(漢字1文字)
|
36
|
+
* %E: 元号の年
|
37
|
+
* %-E: 元号の年(1から9まで1ケタ)
|
38
|
+
* %J: 漢数字
|
36
39
|
|
37
40
|
### Timeインスタンスを和暦に変換します。
|
38
41
|
|
39
42
|
```ruby
|
40
43
|
require 'era_ja'
|
41
|
-
Time.mktime(2012,4,29).to_era # => "H24.
|
42
|
-
Time.mktime(2012,4,29).to_era("%O%E
|
44
|
+
Time.mktime(2012,4,29).to_era # => "H24.04.29"
|
45
|
+
Time.mktime(2012,4,29).to_era("%O%E年%-m月%d日") # => "平成24年4月29日"
|
43
46
|
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
|
44
47
|
```
|
45
48
|
|
@@ -47,8 +50,8 @@ Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年
|
|
47
50
|
|
48
51
|
```ruby
|
49
52
|
require 'era_ja
|
50
|
-
Date.new(2012,4,29).to_era # => "H24.
|
51
|
-
Date.new(2012,4,29).to_era("%O%E
|
53
|
+
Date.new(2012,4,29).to_era # => "H24.04.29"
|
54
|
+
Date.new(2012,4,29).to_era("%O%E年%-m月%d日") # => "平成24年4月29日"
|
52
55
|
Date.new(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
|
53
56
|
```
|
54
57
|
|
@@ -73,12 +76,24 @@ Time.mktime(2012,4,29).to_era("%1O%E年%m月%d日") # => "平24年4月29日"
|
|
73
76
|
|
74
77
|
```ruby
|
75
78
|
require 'era_ja'
|
76
|
-
Time.mktime(2012,4,29).to_era(era_names: { heisei: ['h', '平'] }) # => "h24.
|
77
|
-
Time.mktime(2012,4,29).to_era("%O%E
|
78
|
-
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日", era_names: { heisei: ['h', '平'] })
|
79
|
+
Time.mktime(2012,4,29).to_era(era_names: { heisei: ['h', '平'] }) # => "h24.04.29"
|
80
|
+
Time.mktime(2012,4,29).to_era("%O%E年%-m月%d日", era_names: { heisei: ['h', '平'] }) # => "平24年4月29日"
|
81
|
+
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日", era_names: { heisei: ['h', '平'] }) # => "平二十四年四月二十九日"
|
79
82
|
# same as Date
|
80
83
|
```
|
81
84
|
|
85
|
+
### 元号に変換できるかどうかの判定方法 ###
|
86
|
+
|
87
|
+
日付が元号に変換できるかどうかを判定するために、`era_convertible?` を使うことができます。
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'era_ja'
|
91
|
+
Time.mktime(1868,9,7).era_convertible? #=> false
|
92
|
+
Time.mktime(1868,9,8).era_convertible? #=> true
|
93
|
+
```
|
94
|
+
|
95
|
+
元号に変換できない日付に関しては、[Noteセクション](#note) を参照してください。
|
96
|
+
|
82
97
|
## Support
|
83
98
|
|
84
99
|
問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。 https://github.com/tomiacannondale/era_ja/issues
|
data/README.md
CHANGED
@@ -34,14 +34,15 @@ Extra format strings provided by EraJa#to_era are:
|
|
34
34
|
* %O: era(kanzi)
|
35
35
|
* %1O: era(single kanzi)
|
36
36
|
* %E: era year
|
37
|
+
* %-E: era year(single digit format from 1 to 9)
|
37
38
|
* %J: kanzi numeral
|
38
39
|
|
39
40
|
### Time instance to Japanese era
|
40
41
|
|
41
42
|
```ruby
|
42
43
|
require 'era_ja'
|
43
|
-
Time.mktime(2012,4,29).to_era # => "H24.
|
44
|
-
Time.mktime(2012,4,29).to_era("%O%E
|
44
|
+
Time.mktime(2012,4,29).to_era # => "H24.04.29"
|
45
|
+
Time.mktime(2012,4,29).to_era("%O%E年%-m月%d日") # => "平成24年4月29日"
|
45
46
|
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
|
46
47
|
```
|
47
48
|
|
@@ -49,8 +50,8 @@ Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年
|
|
49
50
|
|
50
51
|
```ruby
|
51
52
|
require 'era_ja'
|
52
|
-
Date.new(2012,4,29).to_era # => "H24.
|
53
|
-
Date.new(2012,4,29).to_era("%O%E
|
53
|
+
Date.new(2012,4,29).to_era # => "H24.04.29"
|
54
|
+
Date.new(2012,4,29).to_era("%O%E年%-m月%d日") # => "平成24年4月29日"
|
54
55
|
Date.new(2012,4,29).to_era("%O%JE年%Jm月%Jd日") # => "平成二十四年四月二十九日"
|
55
56
|
```
|
56
57
|
|
@@ -74,12 +75,24 @@ To convert to custom era strings, you can set `era_names` .
|
|
74
75
|
|
75
76
|
```ruby
|
76
77
|
require 'era_ja'
|
77
|
-
Time.mktime(2012,4,29).to_era(era_names: { heisei: ['h', '平'] }) # => "h24.
|
78
|
-
Time.mktime(2012,4,29).to_era("%O%E
|
79
|
-
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日", era_names: { heisei: ['h', '平'] })
|
78
|
+
Time.mktime(2012,4,29).to_era(era_names: { heisei: ['h', '平'] }) # => "h24.04.29"
|
79
|
+
Time.mktime(2012,4,29).to_era("%O%E年%-m月%d日", era_names: { heisei: ['h', '平'] }) # => "平24年4月29日"
|
80
|
+
Time.mktime(2012,4,29).to_era("%O%JE年%Jm月%Jd日", era_names: { heisei: ['h', '平'] }) # => "平二十四年四月二十九日"
|
80
81
|
# same as Date
|
81
82
|
```
|
82
83
|
|
84
|
+
### Checking a date is convertible ###
|
85
|
+
|
86
|
+
You can use `era_convertible?` to check if a given date is convertible or not.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
require 'era_ja'
|
90
|
+
Time.mktime(1868,9,7).era_convertible? #=> false
|
91
|
+
Time.mktime(1868,9,8).era_convertible? #=> true
|
92
|
+
```
|
93
|
+
|
94
|
+
See [Note](#note) section for more details.
|
95
|
+
|
83
96
|
## Support
|
84
97
|
|
85
98
|
Report issues and feature requests to github Issues. https://github.com/tomiacannondale/era_ja/issues
|
data/era_ja.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = EraJa::VERSION
|
17
17
|
gem.license = "MIT"
|
18
18
|
|
19
|
-
gem.add_development_dependency "rake", '
|
19
|
+
gem.add_development_dependency "rake", '>= 12.3.3'
|
20
20
|
gem.add_development_dependency 'rspec', '~> 3.1.0'
|
21
21
|
gem.add_development_dependency "guard-rspec", '~> 4.5.0'
|
22
22
|
gem.add_development_dependency 'rb-fsevent', '~> 0.9.4'
|
data/lib/era_ja.rb
CHANGED
data/lib/era_ja/conversion.rb
CHANGED
@@ -7,11 +7,10 @@ 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
|
-
ERR_DATE_OUT_OF_RANGE = "#to_era only works on dates after 1868,9,8".freeze
|
14
|
-
|
15
14
|
# Convert to Japanese era.
|
16
15
|
# @param [String] format_string
|
17
16
|
# Time#strftime format string can be used
|
@@ -22,33 +21,39 @@ module EraJa
|
|
22
21
|
# * %J - kanzi number
|
23
22
|
# @param [Hash] era_names
|
24
23
|
# 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`.
|
24
|
+
# key is `:meiji' or `:taisho' or `:showa` or `:heisei` or `:reiwa`.
|
26
25
|
# value is ["alphabet era name"(ex `h`, `s`)(related to `%o`), "multibyte era name"(eg `平`, `昭`)(related to `%O`)].
|
27
26
|
# this argument is same as one element of ERA_NAME_DEFAULTS.
|
28
27
|
# @return [String]
|
29
28
|
def to_era(format = "%o%E.%m.%d", era_names: ERA_NAME_DEFAULTS)
|
29
|
+
raise EraJa::DateOutOfRangeError unless era_convertible?
|
30
|
+
|
30
31
|
@era_format = format.gsub(/%J/, "%J%")
|
31
32
|
str_time = strftime(@era_format)
|
32
|
-
if @era_format =~ /%([
|
33
|
+
if @era_format =~ /%(-?E|[Oo]|1O)/
|
33
34
|
case
|
34
|
-
when self.to_time < ::Time.mktime(1868,9,8)
|
35
|
-
raise ERR_DATE_OUT_OF_RANGE
|
36
35
|
when self.to_time < ::Time.mktime(1912,7,30)
|
37
36
|
str_time = era_year(year - 1867, :meiji, era_names)
|
38
37
|
when self.to_time < ::Time.mktime(1926,12,25)
|
39
38
|
str_time = era_year(year - 1911, :taisho, era_names)
|
40
39
|
when self.to_time < ::Time.mktime(1989,1,8)
|
41
40
|
str_time = era_year(year - 1925, :showa, era_names)
|
42
|
-
|
41
|
+
when self.to_time < ::Time.mktime(2019, 5, 1)
|
43
42
|
str_time = era_year(year - 1988, :heisei, era_names)
|
43
|
+
else
|
44
|
+
str_time = era_year(year - 2018, :reiwa, era_names)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
str_time.gsub(/%J(\d+)/) { to_kanzi($1) }
|
47
48
|
end
|
48
49
|
|
50
|
+
def era_convertible?
|
51
|
+
self.to_time >= ::Time.mktime(1868,9,8)
|
52
|
+
end
|
53
|
+
|
49
54
|
private
|
50
55
|
def era_year(year, era, era_names)
|
51
|
-
strftime(@era_format).sub(/(%J)
|
56
|
+
strftime(@era_format).sub(/(%J)?(%-?E)/) { format_year(year, $1, $2) }.sub(/%1?o/i) { format_era(era, era_names) }
|
52
57
|
end
|
53
58
|
|
54
59
|
def format_era(era, era_names)
|
@@ -62,18 +67,26 @@ module EraJa
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
|
-
def format_year(year, match)
|
70
|
+
def format_year(year, match, digit)
|
66
71
|
era_year = sprintf("%02d", year)
|
72
|
+
|
67
73
|
if match == "%J"
|
68
|
-
|
74
|
+
return year == 1 ? "元" : to_kanzi(era_year)
|
69
75
|
end
|
76
|
+
|
77
|
+
era_year = if digit == "%-E"
|
78
|
+
sprintf("%01d", year)
|
79
|
+
else
|
80
|
+
sprintf("%02d", year)
|
81
|
+
end
|
82
|
+
|
70
83
|
era_year
|
71
84
|
end
|
72
85
|
|
73
86
|
def to_kanzi(numeric, kanzi = "")
|
74
87
|
figures = (10 ** numeric.to_s.size) / 10
|
75
88
|
numeric = numeric.to_i
|
76
|
-
kanzi_string = [
|
89
|
+
kanzi_string = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九"]
|
77
90
|
figures_string = { 1000 => "千", 100 => "百", 10 => "十", 1 => "" }
|
78
91
|
return kanzi + kanzi_string[numeric] if figures == 1
|
79
92
|
|
data/lib/era_ja/error.rb
ADDED
data/lib/era_ja/version.rb
CHANGED
data/spec/date_spec.rb
CHANGED
@@ -5,6 +5,26 @@ 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 2020,1,1" do
|
9
|
+
subject { Date.new(2020,1,1) }
|
10
|
+
include_examples "2020,1,1"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "date is 2019,7,2" do
|
14
|
+
subject { Date.new(2019,7,2) }
|
15
|
+
include_examples "2019,7,2"
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'date is 2019,5,1' do
|
19
|
+
subject { Date.new(2019,5,1) }
|
20
|
+
include_examples "2019,5,1"
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'date is 2019,4,30' do
|
24
|
+
subject { Date.new(2019,4,30) }
|
25
|
+
include_examples "2019,4,30"
|
26
|
+
end
|
27
|
+
|
8
28
|
context "date is 2012,4,29" do
|
9
29
|
subject { Date.new(2012,4,29) }
|
10
30
|
include_examples "2012,4,29"
|
@@ -53,4 +73,20 @@ RSpec.describe Date do
|
|
53
73
|
|
54
74
|
end
|
55
75
|
|
76
|
+
describe "#era_convertible?" do
|
77
|
+
|
78
|
+
context "when date is not convertible" do
|
79
|
+
it "returns false" do
|
80
|
+
expect(Date.new(1868,9,7).era_convertible?).to be false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when date is convertible" do
|
85
|
+
it "returns true" do
|
86
|
+
expect(Date.new(1868,9,8).era_convertible?).to be true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
56
92
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,164 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'rspec'
|
3
|
+
require File.expand_path('../lib/era_ja/error', File.dirname(__FILE__))
|
4
|
+
|
5
|
+
RSpec.shared_examples "should equal 'R01.07.02'" do
|
6
|
+
it { expect(subject.to_era).to eq "R01.07.02" }
|
7
|
+
|
8
|
+
context "with '%o%E.%m.%d'" do
|
9
|
+
it { expect(subject.to_era("%o%E.%m.%d")).to eq "R01.07.02" }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with '%o%-E.%-m.%-d'" do
|
13
|
+
it { expect(subject.to_era("%o%-E.%-m.%-d")).to eq "R1.7.2" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.shared_examples "should equal '令和01年07月02日'" do
|
18
|
+
context "with '%O%E年%m月%d日'" do
|
19
|
+
it { expect(subject.to_era("%O%E年%m月%d日")).to eq "令和01年07月02日" }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with '%O%-E年%m月%d日'" do
|
23
|
+
it { expect(subject.to_era("%O%-E年%m月%d日")).to eq "令和1年07月02日" }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with '%O%J%-E年%m月%d日'" do
|
27
|
+
it { expect(subject.to_era("%O%J%-E年%m月%d日")).to eq "令和元年07月02日" }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with '%-E年%-m月%-d日'" do
|
31
|
+
it { expect(subject.to_era("%-E年%-m月%-d日")).to eq "1年7月2日" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.shared_examples "should equal 'R01.05.01'" do
|
36
|
+
it { expect(subject.to_era).to eq "R01.05.01" }
|
37
|
+
|
38
|
+
context "with '%o%E.%m.%d'" do
|
39
|
+
it { expect(subject.to_era("%o%E.%m.%d")).to eq "R01.05.01" }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.shared_examples "should equal 'r01.05.01'" do
|
44
|
+
context "with era_names option" do
|
45
|
+
context "when era_names is correct" do
|
46
|
+
let(:era_names) { { reiwa: ["r", "令和"] } }
|
47
|
+
it { expect(subject.to_era(era_names: era_names)).to eq "r01.05.01" }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when era_names have no reiwa values" do
|
51
|
+
let(:era_names) { { heisei: ["h", "平成"] } }
|
52
|
+
it { expect { subject.to_era(era_names: era_names) }.to raise_error(KeyError) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with '%o%E.%m.%d' and era_names option" do
|
57
|
+
let(:era_names) { { reiwa: ["r", "令和"] } }
|
58
|
+
it { expect(subject.to_era("%o%E.%m.%d", era_names: era_names)).to eq "r01.05.01" }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
RSpec.shared_examples "should equal '令和01年05月01日'" do
|
63
|
+
context "with '%O%E年%m月%d日'" do
|
64
|
+
it { expect(subject.to_era("%O%E年%m月%d日")).to eq "令和01年05月01日" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
RSpec.shared_examples "should equal '令01年05月01日'" do
|
69
|
+
context "with '%1O%E年%m月%d日'" do
|
70
|
+
it { expect(subject.to_era("%1O%E年%m月%d日")).to eq "令01年05月01日" }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
RSpec.shared_examples "should equal '01.05.01'" do
|
75
|
+
context "with '%E.%m.%d'" do
|
76
|
+
it { expect(subject.to_era("%E.%m.%d")).to eq "01.05.01" }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
RSpec.shared_examples "should equal '0105'" do
|
81
|
+
context "with '%E%m'" do
|
82
|
+
it { expect(subject.to_era("%E%m")).to eq "0105" }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
RSpec.shared_examples "should equal '令和010501'" do
|
87
|
+
context "with '%O%E%m%d'" do
|
88
|
+
it { expect(subject.to_era("%O%E%m%d")).to eq "令和010501" }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
RSpec.shared_examples "should equal '令010501'" do
|
93
|
+
context "with '%O%E%m%d' and era_names option" do
|
94
|
+
let(:format) { "%O%E%m%d" }
|
95
|
+
|
96
|
+
context "when era_names is correct" do
|
97
|
+
let(:era_names) { { reiwa: ["R", "令"] } }
|
98
|
+
it { expect(subject.to_era(format, era_names: era_names)).to eq '令010501' }
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when era_names have no heisei values" do
|
102
|
+
let(:era_names) { { heisei: ["H", "平"] } }
|
103
|
+
it { expect { subject.to_era(format, era_names: era_names) }.to raise_error(KeyError) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
RSpec.shared_examples "should equal '2019年05月01日'" do
|
109
|
+
context "with '%y年%m月%d日'" do
|
110
|
+
it { expect(subject.to_era('%Y年%m月%d日')).to eq '2019年05月01日' }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
RSpec.shared_examples "should equal '令和元年五月一日'" do
|
115
|
+
context "with '%O%JE年%Jm月%Jd日'" do
|
116
|
+
it { expect(subject.to_era('%O%JE年%Jm月%Jd日')).to eq '令和元年五月一日' }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
RSpec.shared_examples "should equal '二千十九年五月一日'" do
|
121
|
+
context "with '%JY年%Jm月%Jd日'" do
|
122
|
+
it { expect(subject.to_era('%JY年%Jm月%Jd日')).to eq '二千十九年五月一日' }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
RSpec.shared_examples "should equal '令和'" do
|
128
|
+
context "with '%O'" do
|
129
|
+
it { expect(subject.to_era('%O')).to eq '令和' }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
RSpec.shared_examples "should equal '令'" do
|
134
|
+
context "with '%1O'" do
|
135
|
+
it { expect(subject.to_era('%1O')).to eq '令' }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
RSpec.shared_examples "should equal 'R'" do
|
140
|
+
context "with '%o'" do
|
141
|
+
it { expect(subject.to_era('%o')).to eq 'R' }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
RSpec.shared_examples "should equal '令和二年一月一日'" do
|
146
|
+
context "with '%O%JE年%Jm月%Jd日'" do
|
147
|
+
it { expect(subject.to_era('%O%JE年%Jm月%Jd日')).to eq '令和二年一月一日' }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
RSpec.shared_examples "should equal '平成三十一年四月三十日'" do
|
152
|
+
context "with '%O%JE年%Jm月%Jd日'" do
|
153
|
+
it { expect(subject.to_era("%O%JE年%Jm月%Jd日")).to eq "平成三十一年四月三十日" }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
RSpec.shared_examples "should equal '二千十九年四月三十日'" do
|
158
|
+
context "with '%JY年%Jm月%Jd日'" do
|
159
|
+
it { expect(subject.to_era("%JY年%Jm月%Jd日")).to eq "二千十九年四月三十日" }
|
160
|
+
end
|
161
|
+
end
|
3
162
|
|
4
163
|
RSpec.shared_examples "should equal 'H24.04.29'" do
|
5
164
|
it { expect(subject.to_era).to eq "H24.04.29" }
|
@@ -169,7 +328,38 @@ RSpec.shared_examples "should equal 'M01.09.08'" do
|
|
169
328
|
end
|
170
329
|
|
171
330
|
RSpec.shared_examples "should raise error" do
|
172
|
-
it { expect {subject.to_era}.to raise_error(
|
331
|
+
it { expect {subject.to_era}.to raise_error(EraJa::DateOutOfRangeError, EraJa::DateOutOfRangeError::ERR_DATE_OUT_OF_RANGE) }
|
332
|
+
end
|
333
|
+
|
334
|
+
RSpec.shared_examples "2020,1,1" do
|
335
|
+
include_examples "should equal '令和二年一月一日'"
|
336
|
+
end
|
337
|
+
|
338
|
+
RSpec.shared_examples "2019,7,2" do
|
339
|
+
include_examples "should equal 'R01.07.02'"
|
340
|
+
include_examples "should equal '令和01年07月02日'"
|
341
|
+
end
|
342
|
+
|
343
|
+
RSpec.shared_examples "2019,5,1" do
|
344
|
+
include_examples "should equal 'R01.05.01'"
|
345
|
+
include_examples "should equal 'r01.05.01'"
|
346
|
+
include_examples "should equal '令和01年05月01日'"
|
347
|
+
include_examples "should equal '令01年05月01日'"
|
348
|
+
include_examples "should equal '01.05.01'"
|
349
|
+
include_examples "should equal '0105'"
|
350
|
+
include_examples "should equal '令和010501'"
|
351
|
+
include_examples "should equal '令010501'"
|
352
|
+
include_examples "should equal '2019年05月01日'"
|
353
|
+
include_examples "should equal '令和元年五月一日'"
|
354
|
+
include_examples "should equal '二千十九年五月一日'"
|
355
|
+
include_examples "should equal '令和'"
|
356
|
+
include_examples "should equal '令'"
|
357
|
+
include_examples "should equal 'R'"
|
358
|
+
end
|
359
|
+
|
360
|
+
RSpec.shared_examples "2019,4,30" do
|
361
|
+
include_examples "should equal '平成三十一年四月三十日'"
|
362
|
+
include_examples "should equal '二千十九年四月三十日'"
|
173
363
|
end
|
174
364
|
|
175
365
|
RSpec.shared_examples "2012,4,29" do
|
data/spec/time_spec.rb
CHANGED
@@ -5,6 +5,26 @@ 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 2020,1,1' do
|
9
|
+
subject { Time.mktime(2020,1,1) }
|
10
|
+
include_examples "2020,1,1"
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'time is 2019,7,2' do
|
14
|
+
subject { Time.mktime(2019,7,2) }
|
15
|
+
include_examples "2019,7,2"
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'time is 2019,5,1' do
|
19
|
+
subject { Time.mktime(2019,5,1) }
|
20
|
+
include_examples "2019,5,1"
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'time is 2019,4,30' do
|
24
|
+
subject { Time.mktime(2019,4,30) }
|
25
|
+
include_examples "2019,4,30"
|
26
|
+
end
|
27
|
+
|
8
28
|
context "time is 2012,4,29" do
|
9
29
|
subject { Time.mktime(2012,4,29) }
|
10
30
|
include_examples "2012,4,29"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: era_ja
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 12.3.3
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 12.3.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/era_ja.rb
|
116
116
|
- lib/era_ja/conversion.rb
|
117
117
|
- lib/era_ja/date.rb
|
118
|
+
- lib/era_ja/error.rb
|
118
119
|
- lib/era_ja/time.rb
|
119
120
|
- lib/era_ja/version.rb
|
120
121
|
- spec/date_spec.rb
|
@@ -124,7 +125,7 @@ homepage: https://github.com/tomiacannondale/era_ja
|
|
124
125
|
licenses:
|
125
126
|
- MIT
|
126
127
|
metadata: {}
|
127
|
-
post_install_message:
|
128
|
+
post_install_message:
|
128
129
|
rdoc_options: []
|
129
130
|
require_paths:
|
130
131
|
- lib
|
@@ -139,9 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
140
|
- !ruby/object:Gem::Version
|
140
141
|
version: '0'
|
141
142
|
requirements: []
|
142
|
-
|
143
|
-
|
144
|
-
signing_key:
|
143
|
+
rubygems_version: 3.1.4
|
144
|
+
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Convert Date or Time instance to String of Japanese era.
|
147
147
|
test_files:
|