era_ja 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/README.ja.md +13 -10
- data/README.md +8 -7
- data/lib/era_ja/conversion.rb +11 -3
- data/lib/era_ja/version.rb +1 -1
- data/spec/spec_helper.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b4e1ea6e0f49b2428040951c2bc627f6f7000c02b9909b4df5420275c6241c
|
4
|
+
data.tar.gz: 77e516fc1ebff2d48ad04ff8bb89af8f3a062ae08edce64f7a21ad354097f888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61cdbea263b6f00aa2b361c57cb01f66c3fc61382584ae8663d1d9cc519499a88ebb5968d131173496ba4cfdc44830cc4cc57c5782d9f6f9a4c243d120495bd3
|
7
|
+
data.tar.gz: 93ec6a7997073615c201a53360f7c82c636905b4a8cd77a341e10130c850fae1ca252bde8be92d8b550a75e0c1f91770532a21ef1a2a5c280275544bd2b484a9
|
data/.travis.yml
CHANGED
data/README.ja.md
CHANGED
@@ -30,16 +30,19 @@
|
|
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,9 +76,9 @@ 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
|
|
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,9 +75,9 @@ 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
|
|
data/lib/era_ja/conversion.rb
CHANGED
@@ -53,7 +53,7 @@ module EraJa
|
|
53
53
|
|
54
54
|
private
|
55
55
|
def era_year(year, era, era_names)
|
56
|
-
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) }
|
57
57
|
end
|
58
58
|
|
59
59
|
def format_era(era, era_names)
|
@@ -67,11 +67,19 @@ module EraJa
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def format_year(year, match)
|
70
|
+
def format_year(year, match, digit)
|
71
71
|
era_year = sprintf("%02d", year)
|
72
|
+
|
72
73
|
if match == "%J"
|
73
|
-
|
74
|
+
return year == 1 ? "元" : to_kanzi(era_year)
|
74
75
|
end
|
76
|
+
|
77
|
+
era_year = if digit == "%-E"
|
78
|
+
sprintf("%01d", year)
|
79
|
+
else
|
80
|
+
sprintf("%02d", year)
|
81
|
+
end
|
82
|
+
|
75
83
|
era_year
|
76
84
|
end
|
77
85
|
|
data/lib/era_ja/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,12 +8,24 @@ RSpec.shared_examples "should equal 'R01.07.02'" do
|
|
8
8
|
context "with '%o%E.%m.%d'" do
|
9
9
|
it { expect(subject.to_era("%o%E.%m.%d")).to eq "R01.07.02" }
|
10
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
|
11
15
|
end
|
12
16
|
|
13
17
|
RSpec.shared_examples "should equal '令和01年07月02日'" do
|
14
18
|
context "with '%O%E年%m月%d日'" do
|
15
19
|
it { expect(subject.to_era("%O%E年%m月%d日")).to eq "令和01年07月02日" }
|
16
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
|
17
29
|
end
|
18
30
|
|
19
31
|
RSpec.shared_examples "should equal 'R01.05.01'" do
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.0.
|
143
|
+
rubygems_version: 3.0.3
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Convert Date or Time instance to String of Japanese era.
|