age_jp 0.0.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 +7 -0
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/age_jp.gemspec +27 -0
- data/lib/age_jp/calculator.rb +90 -0
- data/lib/age_jp/core_ext/date.rb +33 -0
- data/lib/age_jp/version.rb +3 -0
- data/lib/age_jp.rb +6 -0
- data/spec/age_jp_spec.rb +288 -0
- data/spec/spec_helper.rb +3 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f44fd45916598f53ce0643a6a201317d91dc9235
|
4
|
+
data.tar.gz: bb9b82d8350e2f186f47376bad6d071350406be9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 271b86089eb0341b1e3e98fd991595d0d1980155dc750078e6affdca72bfcad1f2baa75bd5d9ea65364305289cbab41619acdbc2a88ec615ddc37ddecc114b7a
|
7
|
+
data.tar.gz: 147d692c51cdce49cba2a29d64f1d37eb67ec9d18c6f90f449086c62cae4bad548f405cdea713d1d53c275e2f0e8772ab8a8fe375ad6b65b6a75cdab0612949c
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.sw*
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
age_jp (0.0.2)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.2.1)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
i18n (0.7.0)
|
18
|
+
json (1.8.2)
|
19
|
+
minitest (5.5.1)
|
20
|
+
rake (10.4.0)
|
21
|
+
rspec (3.1.0)
|
22
|
+
rspec-core (~> 3.1.0)
|
23
|
+
rspec-expectations (~> 3.1.0)
|
24
|
+
rspec-mocks (~> 3.1.0)
|
25
|
+
rspec-core (3.1.7)
|
26
|
+
rspec-support (~> 3.1.0)
|
27
|
+
rspec-expectations (3.1.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.1.0)
|
30
|
+
rspec-mocks (3.1.3)
|
31
|
+
rspec-support (~> 3.1.0)
|
32
|
+
rspec-support (3.1.2)
|
33
|
+
thread_safe (0.3.5)
|
34
|
+
timecop (0.7.1)
|
35
|
+
tzinfo (1.2.2)
|
36
|
+
thread_safe (~> 0.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
age_jp!
|
43
|
+
bundler (~> 1.7)
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec
|
46
|
+
timecop (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ryoff
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# AgeJp
|
2
|
+
|
3
|
+
日本の法律に則った年齢計算です
|
4
|
+
[年齢計算ニ関スル法律 - Wikipedia](http://ja.wikipedia.org/wiki/%E5%B9%B4%E9%BD%A2%E8%A8%88%E7%AE%97%E3%83%8B%E9%96%A2%E3%82%B9%E3%83%AB%E6%B3%95%E5%BE%8B)
|
5
|
+
|
6
|
+
>年を取る日は誕生日の前日となる
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'age_jp'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install age_jp
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```lang:age_jp.rb
|
27
|
+
Timecop.freeze(Time.new(2014, 12, 31))
|
28
|
+
|
29
|
+
birthday = Date.new(2000, 1, 1)
|
30
|
+
birthday.age # 14 (通常の年齢)
|
31
|
+
birthday.age_at(date) # same as birthday.age_at(Date.today)
|
32
|
+
birthday.age_jp # 15 (日本の法律準拠)
|
33
|
+
birthday.age_jp_at(date) # same as birthday.age_jp_at(Date.today)
|
34
|
+
birthday.east_asian_age_reckoning # 15 (数え年)
|
35
|
+
birthday.east_asian_age_reckoning_at(date) # same as birthday.east_asian_age_reckoning_at(Date.today)
|
36
|
+
birthday.to_years_old(17) # 2017/01/01. 17歳の誕生日を返却
|
37
|
+
birthday.to_years_old_jp(17) # 2016/12/31. 17歳の年齢加算日(日本の法律準拠)を返却
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/[my-github-username]/age_jp/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/age_jp.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'age_jp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "age_jp"
|
8
|
+
spec.version = AgeJp::VERSION
|
9
|
+
spec.authors = ["ryoff"]
|
10
|
+
spec.email = ["ryoffes@gmail.com"]
|
11
|
+
spec.summary = %q{A simpel age calculator for a law of Japan.}
|
12
|
+
spec.description = %q{A simpel age calculator for a law of Japan.}
|
13
|
+
spec.homepage = "https://github.com/ryoff/age_jp"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "timecop", '~> 0.7'
|
27
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module AgeJp
|
2
|
+
class Calculator
|
3
|
+
def initialize(birthday)
|
4
|
+
@birthday = birthday
|
5
|
+
end
|
6
|
+
|
7
|
+
def age
|
8
|
+
return unless valid_birthday?
|
9
|
+
|
10
|
+
calculate_age(today)
|
11
|
+
end
|
12
|
+
|
13
|
+
def age_at(date)
|
14
|
+
return unless valid_birthday? && valid_date?(date)
|
15
|
+
|
16
|
+
calculate_age(date)
|
17
|
+
end
|
18
|
+
|
19
|
+
def age_jp
|
20
|
+
return unless valid_birthday?
|
21
|
+
|
22
|
+
calculate_age_jp(today)
|
23
|
+
end
|
24
|
+
|
25
|
+
def age_jp_at(date)
|
26
|
+
return unless valid_birthday? && valid_date?(date)
|
27
|
+
|
28
|
+
calculate_age_jp(date)
|
29
|
+
end
|
30
|
+
|
31
|
+
def east_asian_age_reckoning
|
32
|
+
return unless valid_birthday?
|
33
|
+
|
34
|
+
age = calculate_age(today)
|
35
|
+
until_birthday_this_year?(today) ? age + 2 : age + 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def east_asian_age_reckoning_at(date)
|
39
|
+
return unless valid_birthday? && valid_date?(date)
|
40
|
+
|
41
|
+
age = calculate_age(date)
|
42
|
+
until_birthday_this_year?(date) ? age + 2 : age + 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def today
|
46
|
+
Date.today
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def calculate_age_jp(date)
|
52
|
+
# 誕生日が閏日の場合は、日本の民法ではdateが閏年であろうとなかろうと、2/28に年齢加算される
|
53
|
+
# つまり、誕生日が閏日 かつ dateが2/27の場合は、閏年であろうと無かろうと、年齢加算しない
|
54
|
+
return calculate_age(date) if leap_date?(@birthday) && february_twenty_seven?(date)
|
55
|
+
|
56
|
+
(calculate_age(date) - calculate_age(date.tomorrow)).zero? ? calculate_age(date) : calculate_age(date.tomorrow)
|
57
|
+
end
|
58
|
+
|
59
|
+
def calculate_age(date)
|
60
|
+
date_ymd_to_i = date.strftime('%Y%m%d').to_i
|
61
|
+
birthday_ymd_to_i = @birthday.strftime('%Y%m%d').to_i
|
62
|
+
|
63
|
+
# 誕生日が閏日 かつ dateが閏年ではない場合
|
64
|
+
birthday_ymd_to_i -= 1 if leap_date?(@birthday) && !date.leap?
|
65
|
+
|
66
|
+
(date_ymd_to_i - birthday_ymd_to_i) / 10_000
|
67
|
+
end
|
68
|
+
|
69
|
+
def until_birthday_this_year?(date)
|
70
|
+
date.strftime('%m%d').to_i < @birthday.strftime('%m%d').to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
def valid_birthday?
|
74
|
+
valid_date?(@birthday)
|
75
|
+
end
|
76
|
+
|
77
|
+
def valid_date?(date)
|
78
|
+
raise ArgumentError, 'invalid date' unless date && date.is_a?(Date)
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def leap_date?(date)
|
83
|
+
date.leap? && date.month == 2 && date.day == 29
|
84
|
+
end
|
85
|
+
|
86
|
+
def february_twenty_seven?(date)
|
87
|
+
date.month == 2 && date.day == 27
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Date
|
2
|
+
def age
|
3
|
+
AgeJp::Calculator.new(self).age
|
4
|
+
end
|
5
|
+
|
6
|
+
def age_at(date)
|
7
|
+
AgeJp::Calculator.new(self).age_at(date)
|
8
|
+
end
|
9
|
+
|
10
|
+
def age_jp
|
11
|
+
AgeJp::Calculator.new(self).age_jp
|
12
|
+
end
|
13
|
+
|
14
|
+
def age_jp_at(date)
|
15
|
+
AgeJp::Calculator.new(self).age_jp_at(date)
|
16
|
+
end
|
17
|
+
|
18
|
+
def east_asian_age_reckoning
|
19
|
+
AgeJp::Calculator.new(self).east_asian_age_reckoning
|
20
|
+
end
|
21
|
+
|
22
|
+
def east_asian_age_reckoning_at(date)
|
23
|
+
AgeJp::Calculator.new(self).east_asian_age_reckoning_at(date)
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :to_years_old, :next_year
|
27
|
+
|
28
|
+
def to_years_old_jp(n)
|
29
|
+
return to_years_old(n).change(day: 28) if leap? && month == 2 && day == 29
|
30
|
+
|
31
|
+
to_years_old(n).yesterday
|
32
|
+
end
|
33
|
+
end
|
data/lib/age_jp.rb
ADDED
data/spec/age_jp_spec.rb
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AgeJp do
|
4
|
+
describe '#age' do
|
5
|
+
context "birthday is 2000/01/01. " do
|
6
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
7
|
+
subject(:age) { birthday.age }
|
8
|
+
|
9
|
+
context 'when today is 2014/12/30' do
|
10
|
+
before { Timecop.freeze(Date.new(2014, 12, 30)) }
|
11
|
+
|
12
|
+
it { expect(age).to eq 14 }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when today is 2014/12/31' do
|
16
|
+
before { Timecop.freeze(Date.new(2014, 12, 31)) }
|
17
|
+
|
18
|
+
it { expect(age).to eq 14 }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when today is 2015/1/1' do
|
22
|
+
before { Timecop.freeze(Date.new(2015, 1, 1)) }
|
23
|
+
|
24
|
+
it { expect(age).to eq 15 }
|
25
|
+
end
|
26
|
+
|
27
|
+
after { Timecop.return }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "birthday is 2000/02/29. " do
|
31
|
+
let(:birthday) { Date.new(2000, 2, 29) }
|
32
|
+
subject(:age) { birthday.age }
|
33
|
+
|
34
|
+
context 'when today is 2015/02/28' do
|
35
|
+
before { Timecop.freeze(Date.new(2015, 2, 28)) }
|
36
|
+
|
37
|
+
it { expect(age).to eq 15 }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when today is 2016/02/28' do
|
41
|
+
before { Timecop.freeze(Date.new(2016, 2, 28)) }
|
42
|
+
|
43
|
+
it { expect(age).to eq 15 }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when today is 2016/2/29' do
|
47
|
+
before { Timecop.freeze(Date.new(2016, 2, 29)) }
|
48
|
+
|
49
|
+
it { expect(age).to eq 16 }
|
50
|
+
end
|
51
|
+
|
52
|
+
after { Timecop.return }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#age_at' do
|
57
|
+
context "birthday is 2000/01/01. " do
|
58
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
59
|
+
subject(:age_at) { birthday.age_at(today) }
|
60
|
+
|
61
|
+
context 'when date is 2016/12/30' do
|
62
|
+
let(:today) { Date.new(2016, 12, 30) }
|
63
|
+
|
64
|
+
it { expect(age_at).to eq 16 }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when date is 2016/12/31' do
|
68
|
+
let(:today) { Date.new(2016, 12, 31) }
|
69
|
+
|
70
|
+
it { expect(age_at).to eq 16 }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when date is 2017/1/1' do
|
74
|
+
let(:today) { Date.new(2017, 1, 1) }
|
75
|
+
|
76
|
+
it { expect(age_at).to eq 17 }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#age_jp' do
|
82
|
+
context "birthday is 2000/01/01. " do
|
83
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
84
|
+
subject(:age_jp) { birthday.age_jp }
|
85
|
+
|
86
|
+
context 'when today is 2014/12/30' do
|
87
|
+
before { Timecop.freeze(Date.new(2014, 12, 30)) }
|
88
|
+
|
89
|
+
it { expect(age_jp).to eq 14 }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when today is 2014/12/31' do
|
93
|
+
before { Timecop.freeze(Date.new(2014, 12, 31)) }
|
94
|
+
|
95
|
+
it { expect(age_jp).to eq 15 }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when today is 2015/1/1' do
|
99
|
+
before { Timecop.freeze(Date.new(2015, 1, 1)) }
|
100
|
+
|
101
|
+
it { expect(age_jp).to eq 15 }
|
102
|
+
end
|
103
|
+
|
104
|
+
after { Timecop.return }
|
105
|
+
end
|
106
|
+
|
107
|
+
context "birthday is 2000/02/29. " do
|
108
|
+
let(:birthday) { Date.new(2000, 2, 29) }
|
109
|
+
subject(:age_jp) { birthday.age_jp }
|
110
|
+
|
111
|
+
context 'when today is 2015/02/27' do
|
112
|
+
before { Timecop.freeze(Date.new(2015, 2, 27)) }
|
113
|
+
|
114
|
+
it { expect(age_jp).to eq 14 }
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when today is 2015/02/28' do
|
118
|
+
before { Timecop.freeze(Date.new(2015, 2, 28)) }
|
119
|
+
|
120
|
+
it { expect(age_jp).to eq 15 }
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when today is 2016/02/28' do
|
124
|
+
before { Timecop.freeze(Date.new(2016, 2, 28)) }
|
125
|
+
|
126
|
+
it { expect(age_jp).to eq 16 }
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when today is 2016/2/29' do
|
130
|
+
before { Timecop.freeze(Date.new(2016, 2, 29)) }
|
131
|
+
|
132
|
+
it { expect(age_jp).to eq 16 }
|
133
|
+
end
|
134
|
+
|
135
|
+
after { Timecop.return }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#age_jp_at' do
|
140
|
+
context "birthday is 2000/01/01. " do
|
141
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
142
|
+
subject(:age_jp_at) { birthday.age_jp_at(today) }
|
143
|
+
|
144
|
+
context 'when date is 2016/12/30' do
|
145
|
+
let(:today) { Date.new(2016, 12, 30) }
|
146
|
+
|
147
|
+
it { expect(age_jp_at).to eq 16 }
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when date is 2016/12/31' do
|
151
|
+
let(:today) { Date.new(2016, 12, 31) }
|
152
|
+
|
153
|
+
it { expect(age_jp_at).to eq 17 }
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when date is 2017/1/1' do
|
157
|
+
let(:today) { Date.new(2017, 1, 1) }
|
158
|
+
|
159
|
+
it { expect(age_jp_at).to eq 17 }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#east_asian_age_reckoning' do
|
165
|
+
context "birthday is 1999/12/31. " do
|
166
|
+
let(:birthday) { Date.new(1999, 12, 31) }
|
167
|
+
|
168
|
+
subject(:east_asian_age_reckoning) { birthday.east_asian_age_reckoning }
|
169
|
+
|
170
|
+
context 'when today is 1999/12/31' do
|
171
|
+
before { Timecop.freeze(Date.new(1999, 12, 31)) }
|
172
|
+
|
173
|
+
it { expect(east_asian_age_reckoning).to eq 1 }
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when today is 2000/01/01' do
|
177
|
+
before { Timecop.freeze(Date.new(2000, 1, 1)) }
|
178
|
+
|
179
|
+
it { expect(east_asian_age_reckoning).to eq 2 }
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when today is 2000/12/31' do
|
183
|
+
before { Timecop.freeze(Date.new(2000, 12, 31)) }
|
184
|
+
|
185
|
+
it { expect(east_asian_age_reckoning).to eq 2 }
|
186
|
+
end
|
187
|
+
|
188
|
+
after { Timecop.return }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#east_asian_age_reckoning_at' do
|
193
|
+
context "birthday is 1999/12/31. " do
|
194
|
+
let(:birthday) { Date.new(1999, 12, 31) }
|
195
|
+
subject(:east_asian_age_reckoning_at) { birthday.east_asian_age_reckoning_at(today) }
|
196
|
+
|
197
|
+
context 'when date is 2016/12/31' do
|
198
|
+
let(:today) { Date.new(2016, 12, 31) }
|
199
|
+
|
200
|
+
it { expect(east_asian_age_reckoning_at).to eq 18 }
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when date is 2017/01/01' do
|
204
|
+
let(:today) { Date.new(2017, 1, 1) }
|
205
|
+
|
206
|
+
it { expect(east_asian_age_reckoning_at).to eq 19 }
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'when date is 2017/12/31' do
|
210
|
+
let(:today) { Date.new(2017, 12, 31) }
|
211
|
+
|
212
|
+
it { expect(east_asian_age_reckoning_at).to eq 19 }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#to_years_old' do
|
218
|
+
subject { birthday.to_years_old(year) }
|
219
|
+
|
220
|
+
context 'with birthday is 2000/01/01' do
|
221
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
222
|
+
|
223
|
+
context 'with year is 16' do
|
224
|
+
let(:year) { 16 }
|
225
|
+
|
226
|
+
it { is_expected.to eq Date.new(2016, 1, 1) }
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'with year is 17' do
|
230
|
+
let(:year) { 17 }
|
231
|
+
|
232
|
+
it { is_expected.to eq Date.new(2017, 1, 1) }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'with birthday is 2000/02/29' do
|
237
|
+
let(:birthday) { Date.new(2000, 2, 29) }
|
238
|
+
|
239
|
+
context 'with year is 16' do
|
240
|
+
let(:year) { 16 }
|
241
|
+
|
242
|
+
it { is_expected.to eq Date.new(2016, 2, 29) }
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'with year is 17' do
|
246
|
+
let(:year) { 17 }
|
247
|
+
|
248
|
+
it { is_expected.to eq Date.new(2017, 2, 28) }
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe '#to_years_old_jp' do
|
254
|
+
subject { birthday.to_years_old_jp(year) }
|
255
|
+
|
256
|
+
context 'with birthday is 2000/01/01' do
|
257
|
+
let(:birthday) { Date.new(2000, 1, 1) }
|
258
|
+
|
259
|
+
context 'with year is 16' do
|
260
|
+
let(:year) { 16 }
|
261
|
+
|
262
|
+
it { is_expected.to eq Date.new(2015, 12, 31) }
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'with year is 17' do
|
266
|
+
let(:year) { 17 }
|
267
|
+
|
268
|
+
it { is_expected.to eq Date.new(2016, 12, 31) }
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'with birthday is 2000/02/29' do
|
273
|
+
let(:birthday) { Date.new(2000, 2, 29) }
|
274
|
+
|
275
|
+
context 'with year is 16' do
|
276
|
+
let(:year) { 16 }
|
277
|
+
|
278
|
+
it { is_expected.to eq Date.new(2016, 2, 28) }
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'with year is 17' do
|
282
|
+
let(:year) { 17 }
|
283
|
+
|
284
|
+
it { is_expected.to eq Date.new(2017, 2, 28) }
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: age_jp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryoff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
description: A simpel age calculator for a law of Japan.
|
84
|
+
email:
|
85
|
+
- ryoffes@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- age_jp.gemspec
|
98
|
+
- lib/age_jp.rb
|
99
|
+
- lib/age_jp/calculator.rb
|
100
|
+
- lib/age_jp/core_ext/date.rb
|
101
|
+
- lib/age_jp/version.rb
|
102
|
+
- spec/age_jp_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/ryoff/age_jp
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A simpel age calculator for a law of Japan.
|
128
|
+
test_files:
|
129
|
+
- spec/age_jp_spec.rb
|
130
|
+
- spec/spec_helper.rb
|