japanese_calendar 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +17 -14
- data/japanese_calendar.gemspec +3 -3
- data/lib/japanese_calendar/core_ext/date.rb +9 -0
- data/lib/japanese_calendar/core_ext/date_time.rb +9 -0
- data/lib/japanese_calendar/era.rb +60 -21
- data/lib/japanese_calendar/version.rb +1 -1
- data/lib/japanese_calendar/weekday.rb +18 -4
- data/lib/japanese_calendar.rb +2 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d6bd70c70fd16b249bd21b5d7859ead4d393887170bbd28734cc58df5b6397dd
|
4
|
+
data.tar.gz: d1c54d42d05800862841d3f22c1b4be0ddb2f1282dfd7222abcfe36cbdbcf5ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736514a1cbce60600b39dc1a96aeb816b2c7f31d8297f720ca903d851eca7454f2c4785e5a514d189a7ada6f515c9f5648ed72c305b09e07771f4efbcde7f0c7
|
7
|
+
data.tar.gz: d3b12a19c5a160d85483410f79fc9a7974ebacf64e2225c0aa28f7c56b0293769fe4c6b7f63f69a9629bb1863dba04c3178fda888d88a6c4b0f17988cd7307d7
|
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
before_install: gem install bundler -v
|
4
|
+
- 2.3.8
|
5
|
+
- 2.4.6
|
6
|
+
- 2.5.5
|
7
|
+
- 2.6.2
|
8
|
+
before_install: gem install bundler -v 2.0.1
|
9
9
|
addons:
|
10
10
|
code_climate:
|
11
11
|
repo_token: c542293583b86ca95015675c334c9fea63c14825709f7c9eb4c72a0c8cfc71b4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,7 @@ Or install it yourself as:
|
|
23
23
|
To get the Japanese era name, use the `era_name` method:
|
24
24
|
|
25
25
|
```
|
26
|
+
Time.new(2019, 5, 1).era_name # => "令和"
|
26
27
|
Time.new(1989, 1, 8).era_name # => "平成"
|
27
28
|
Time.new(1926, 12, 25).era_name # => "昭和"
|
28
29
|
Time.new(1912, 7, 30).era_name # => "大正"
|
@@ -32,6 +33,7 @@ Time.new(1873, 1, 1).era_name # => "明治"
|
|
32
33
|
If you want to get the Japanese era name in romaji, pass `:romaji`:
|
33
34
|
|
34
35
|
```
|
36
|
+
Time.new(2019, 5, 1).era_name(:romaji) # => "Reiwa"
|
35
37
|
Time.new(1989, 1, 8).era_name(:romaji) # => "Heisei"
|
36
38
|
Time.new(1926, 12, 25).era_name(:romaji) # => "Showa"
|
37
39
|
Time.new(1912, 7, 30).era_name(:romaji) # => "Taisho"
|
@@ -41,7 +43,8 @@ Time.new(1873, 1, 1).era_name(:romaji) # => "Meiji"
|
|
41
43
|
You can convert to a Japanese year with the `era_year` method:
|
42
44
|
|
43
45
|
```
|
44
|
-
Time.new(
|
46
|
+
Time.new(2019, 5, 1).era_year # => 1
|
47
|
+
Time.new(2019, 4, 30).era_year # => 31
|
45
48
|
Time.new(1989, 1, 7).era_year # => 64
|
46
49
|
Time.new(1926, 12, 24).era_year # => 15
|
47
50
|
Time.new(1912, 7, 29).era_year # => 45
|
@@ -50,25 +53,25 @@ Time.new(1912, 7, 29).era_year # => 45
|
|
50
53
|
To get a string representation of the Japanese calendar, use the `strftime` method:
|
51
54
|
|
52
55
|
```
|
53
|
-
time = Time.new(
|
56
|
+
time = Time.new(2019, 5, 1)
|
54
57
|
|
55
58
|
# Japanese era
|
56
|
-
time.strftime("%
|
57
|
-
time.strftime("%
|
58
|
-
time.strftime("%^
|
59
|
-
time.strftime("%
|
60
|
-
time.strftime("%
|
61
|
-
time.strftime("%-
|
62
|
-
time.strftime("%
|
59
|
+
time.strftime("%JN") # => "令和"
|
60
|
+
time.strftime("%JR") # => "Reiwa"
|
61
|
+
time.strftime("%^JR") # => "REIWA"
|
62
|
+
time.strftime("%Jr") # => "R"
|
63
|
+
time.strftime("%Jy") # => "01"
|
64
|
+
time.strftime("%-Jy") # => "1"
|
65
|
+
time.strftime("%_Jy") # => " 1"
|
63
66
|
|
64
67
|
# Japanese weekday name
|
65
|
-
time.strftime("%
|
66
|
-
time.strftime("%
|
68
|
+
time.strftime("%JA") # => "水曜日"
|
69
|
+
time.strftime("%Ja") # => "水"
|
67
70
|
|
68
71
|
# More examples
|
69
|
-
time.strftime("%
|
70
|
-
time.strftime("%
|
71
|
-
time.strftime("%B %-d, %-Y (%
|
72
|
+
time.strftime("%JN%-Jy年%-m月%-d日(%Ja)") # => "令和1年5月1日(水)"
|
73
|
+
time.strftime("%Jr%Jy.%m.%d") # => "R01.05.01"
|
74
|
+
time.strftime("%B %-d, %-Y (%JR %-Jy)") # => "May 1, 2019 (Reiwa 1)"
|
72
75
|
```
|
73
76
|
|
74
77
|
## Development
|
data/japanese_calendar.gemspec
CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.required_ruby_version = ">= 2.
|
24
|
+
spec.required_ruby_version = ">= 2.3"
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
27
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
spec.add_development_dependency "rubocop"
|
30
30
|
spec.add_development_dependency "simplecov"
|
@@ -48,26 +48,28 @@ module JapaneseCalendar
|
|
48
48
|
#
|
49
49
|
# date_of_birth = Time.new(1978, 7, 19)
|
50
50
|
#
|
51
|
-
# date_of_birth.strftime("%
|
52
|
-
# date_of_birth.strftime("%
|
53
|
-
# date_of_birth.strftime("%^
|
54
|
-
# date_of_birth.strftime("%
|
55
|
-
# date_of_birth.strftime("%
|
51
|
+
# date_of_birth.strftime("%JN") # => "昭和"
|
52
|
+
# date_of_birth.strftime("%JR") # => "Showa"
|
53
|
+
# date_of_birth.strftime("%^JR") # => "SHOWA"
|
54
|
+
# date_of_birth.strftime("%Jr") # => "S"
|
55
|
+
# date_of_birth.strftime("%Jy") # => "53"
|
56
56
|
#
|
57
|
-
# date_of_birth.strftime("%
|
57
|
+
# date_of_birth.strftime("%JN%-Jy年") # => "昭和53年"
|
58
58
|
#
|
59
59
|
# Raises an error when the Japanese year cannot be found.
|
60
60
|
#
|
61
|
-
# Time.new(1872, 12, 31).strftime("%
|
61
|
+
# Time.new(1872, 12, 31).strftime("%JN%-Jy年") # => RuntimeError
|
62
62
|
def strftime(format)
|
63
63
|
string = format.dup
|
64
|
-
string.gsub!(/%
|
65
|
-
string.gsub!(/%
|
66
|
-
string.gsub!(/%\^
|
67
|
-
string.gsub!(/%
|
68
|
-
string.gsub!(/%
|
69
|
-
string.gsub!(/%-
|
70
|
-
string.gsub!(/%
|
64
|
+
string.gsub!(/%JN/, era_name)
|
65
|
+
string.gsub!(/%JR/, era_name(:romaji))
|
66
|
+
string.gsub!(/%\^JR/, era_name(:romaji).upcase)
|
67
|
+
string.gsub!(/%Jr/, era_name(:romaji)[0])
|
68
|
+
string.gsub!(/%Jy/, "%02d" % era_year)
|
69
|
+
string.gsub!(/%-Jy/, "%d" % era_year)
|
70
|
+
string.gsub!(/%_Jy/, "%2d" % era_year)
|
71
|
+
deprecated_japanese_calendar_era_name_strftime(string)
|
72
|
+
deprecated_japanese_calendar_era_year_strftime(string)
|
71
73
|
super(string)
|
72
74
|
end
|
73
75
|
|
@@ -76,18 +78,55 @@ module JapaneseCalendar
|
|
76
78
|
Period = Struct.new(:beginning_of_period, :kanji_name, :romaji_name)
|
77
79
|
|
78
80
|
PERIODS = [
|
79
|
-
Period.new(
|
80
|
-
Period.new(
|
81
|
-
Period.new(
|
82
|
-
Period.new(
|
81
|
+
Period.new(Date.new(2019, 5, 1), "令和", "Reiwa").freeze,
|
82
|
+
Period.new(Date.new(1989, 1, 8), "平成", "Heisei").freeze,
|
83
|
+
Period.new(Date.new(1926, 12, 25), "昭和", "Showa" ).freeze,
|
84
|
+
Period.new(Date.new(1912, 7, 30), "大正", "Taisho").freeze,
|
85
|
+
Period.new(Date.new(1868, 1, 25), "明治", "Meiji" ).freeze
|
83
86
|
].freeze
|
84
87
|
|
85
|
-
MEIJI_6 =
|
88
|
+
MEIJI_6 = Date.new(1873, 1, 1)
|
86
89
|
|
87
90
|
def current_era
|
88
91
|
error_proc = proc { raise "#{self.class.name.downcase} out of range" }
|
89
|
-
error_proc.call if self < MEIJI_6
|
90
|
-
PERIODS.find(error_proc)
|
92
|
+
error_proc.call if self.to_date < MEIJI_6
|
93
|
+
PERIODS.find(error_proc) do |period|
|
94
|
+
period.beginning_of_period <= self.to_date
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def deprecated_japanese_calendar_era_name_strftime(string)
|
99
|
+
if string =~ /%K/
|
100
|
+
warn "%K is deprecated. Please use %JN instead."
|
101
|
+
string.gsub!(/%K/, era_name)
|
102
|
+
end
|
103
|
+
if string =~ /%O/
|
104
|
+
warn "%O is deprecated. Please use %JR instead."
|
105
|
+
string.gsub!(/%O/, era_name(:romaji))
|
106
|
+
end
|
107
|
+
if string =~ /%\^O/
|
108
|
+
warn "%^O is deprecated. Please use %^JR instead."
|
109
|
+
string.gsub!(/%\^O/, era_name(:romaji).upcase)
|
110
|
+
end
|
111
|
+
if string =~ /%o/
|
112
|
+
warn "%o is deprecated. Please use %Jr instead."
|
113
|
+
string.gsub!(/%o/, era_name(:romaji)[0])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def deprecated_japanese_calendar_era_year_strftime(string)
|
118
|
+
if string =~ /%J/
|
119
|
+
warn "%J is deprecated. Please use %Jy instead."
|
120
|
+
string.gsub!(/%J/, "%02d" % era_year)
|
121
|
+
end
|
122
|
+
if string =~ /%-J/
|
123
|
+
warn "%-J is deprecated. Please use %-Jy instead."
|
124
|
+
string.gsub!(/%-J/, "%d" % era_year)
|
125
|
+
end
|
126
|
+
if string =~ /%_J/
|
127
|
+
warn "%_J is deprecated. Please use %_Jy instead."
|
128
|
+
string.gsub!(/%_J/, "%2d" % era_year)
|
129
|
+
end
|
91
130
|
end
|
92
131
|
end
|
93
132
|
end
|
@@ -7,15 +7,29 @@ module JapaneseCalendar
|
|
7
7
|
#
|
8
8
|
# date_of_birth = Time.new(1978, 7, 19)
|
9
9
|
#
|
10
|
-
# date_of_birth.strftime("%
|
11
|
-
# date_of_birth.strftime("%
|
10
|
+
# date_of_birth.strftime("%JA") # => "水曜日"
|
11
|
+
# date_of_birth.strftime("%Ja") # => "水"
|
12
12
|
#
|
13
13
|
# date_of_birth.strftime("%-Y年%-m月%-d日(%q)") # => "1978年7月19日(水)"
|
14
14
|
def strftime(format)
|
15
15
|
string = format.dup
|
16
|
-
string.gsub!(/%
|
17
|
-
string.gsub!(/%
|
16
|
+
string.gsub!(/%JA/, NAMES[wday])
|
17
|
+
string.gsub!(/%Ja/, NAMES[wday][0])
|
18
|
+
deprecated_japanese_calendar_weekday_strftime(string)
|
18
19
|
super(string)
|
19
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def deprecated_japanese_calendar_weekday_strftime(string)
|
25
|
+
if string =~ /%Q/
|
26
|
+
warn "%Q is deprecated. Please use %JA instead."
|
27
|
+
string.gsub!(/%Q/, NAMES[wday])
|
28
|
+
end
|
29
|
+
if string =~ /%q/
|
30
|
+
warn "%q is deprecated. Please use %Ja instead."
|
31
|
+
string.gsub!(/%q/, NAMES[wday][0])
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
data/lib/japanese_calendar.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: japanese_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
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: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +117,8 @@ files:
|
|
117
117
|
- exe/japanese_calendar
|
118
118
|
- japanese_calendar.gemspec
|
119
119
|
- lib/japanese_calendar.rb
|
120
|
+
- lib/japanese_calendar/core_ext/date.rb
|
121
|
+
- lib/japanese_calendar/core_ext/date_time.rb
|
120
122
|
- lib/japanese_calendar/core_ext/time.rb
|
121
123
|
- lib/japanese_calendar/era.rb
|
122
124
|
- lib/japanese_calendar/version.rb
|
@@ -133,15 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
135
|
requirements:
|
134
136
|
- - ">="
|
135
137
|
- !ruby/object:Gem::Version
|
136
|
-
version: '2.
|
138
|
+
version: '2.3'
|
137
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
140
|
requirements:
|
139
141
|
- - ">="
|
140
142
|
- !ruby/object:Gem::Version
|
141
143
|
version: '0'
|
142
144
|
requirements: []
|
143
|
-
|
144
|
-
rubygems_version: 2.6.8
|
145
|
+
rubygems_version: 3.0.3
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: Japanese calendar utility for Ruby
|