years 0.0.1
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 +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/lib/years.rb +55 -0
- data/lib/years/version.rb +3 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/years_spec.rb +73 -0
- data/years.gemspec +27 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: acf6659537b23e76f768d32bc8cb5b326f0afc01
|
4
|
+
data.tar.gz: 35b5b8c9f1b5ae6cfe0bf302aba33728cc5092ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7315f4470add7978de59f7d2c4fbd570f863066345056fdcd288adb332b575e8907506a701e83756a60dd3aa0cab17f44cb18cb0f312ed91cf8ead598777b7d0
|
7
|
+
data.tar.gz: 97cfcb2715fb97ee058037a3a7a20370925f1cbdf8b3d1c59a194e2af4bef51ebfb6d94c2bc2fcace35d58a6a6dcb99e6870e4cf3431f2e7e7cdfc49b1bb9f7a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
years
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p353
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nigel Lowry
|
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,36 @@
|
|
1
|
+
# Years
|
2
|
+
|
3
|
+
Small gem for year related methods. Includes a method for calculating a person's age and another for helping create
|
4
|
+
a year range (say for a Web site's copyright statement). Two methods exist for calculating the age for when the
|
5
|
+
legal leapling birthday is 28 Feb (NZ) or 1 Mar (UK). Please check your country's rules.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'years'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install years
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'years'
|
25
|
+
|
26
|
+
Years.age_where_leapling_legal_birthday_is_1_mar('22 Sep 1976'.to_date) # == 37 when the current date is 26 Jan 14
|
27
|
+
Years.range(2012) # == '2012–2014' when the current year is 2014
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( http://github.com/nigel-lowry/years/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/years.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'years/version'
|
2
|
+
|
3
|
+
# Provides some year-related methods.
|
4
|
+
module Years
|
5
|
+
@@EN_DASH = '–'
|
6
|
+
|
7
|
+
# tells the age of someone, with truncation, where the leapling legal birthday is 28 February
|
8
|
+
# @param [Date] date_of_birth the person's date of birth
|
9
|
+
# @param [Date] today the day that you want to know their date of birth for, defaults to today
|
10
|
+
# @return [Fixnum]
|
11
|
+
def self.age_where_leapling_legal_birthday_is_28_feb date_of_birth, today=Date.current
|
12
|
+
age date_of_birth, today, :feb28
|
13
|
+
end
|
14
|
+
|
15
|
+
# tells the age of someone, with truncation, where the leapling legal birthday is 1 March
|
16
|
+
# @param (see Years.age_where_leapling_legal_birthday_is_28_feb)
|
17
|
+
# @param (see Years.age_where_leapling_legal_birthday_is_28_feb)
|
18
|
+
# @return (see Years.age_where_leapling_legal_birthday_is_28_feb)
|
19
|
+
def self.age_where_leapling_legal_birthday_is_1_mar date_of_birth, today=Date.current
|
20
|
+
age date_of_birth, today, :mar1
|
21
|
+
end
|
22
|
+
|
23
|
+
# tells the age of someone, with truncation, where the leapling legal birthday is 28 February
|
24
|
+
# @param [Fixnum] first_year the first year of the range, say the year of company creation
|
25
|
+
# @param [Fixnum] last_year the last year of the range, defaults to this year
|
26
|
+
# @return [String]
|
27
|
+
def self.range first_year, last_year=Date.current.year
|
28
|
+
raise if first_year > last_year
|
29
|
+
|
30
|
+
(first_year == last_year) ? first_year.to_s : first_year.to_s + @@EN_DASH + last_year.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.age date_of_birth, today, legal_leapling_birthday
|
36
|
+
raise if today < date_of_birth
|
37
|
+
|
38
|
+
years = today.year - date_of_birth.year
|
39
|
+
(birthday(date_of_birth, years, legal_leapling_birthday) > today) ? years - 1 : years
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.birthday date_of_birth, years, legal_leapling_birthday
|
43
|
+
bday = date_of_birth.years_since years
|
44
|
+
(leapling?(date_of_birth) and legal_leapling_birthday == :mar1) ? bday.tomorrow : bday
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.leapling? date
|
48
|
+
february_29th? date
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.february_29th? date
|
52
|
+
date.mday == 29 and date.mon == 2
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
data/spec/years_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'years'
|
5
|
+
|
6
|
+
describe Years do
|
7
|
+
describe ".age_where_leapling_legal_birthday_is_1_mar" do
|
8
|
+
context "regular birthday" do
|
9
|
+
let(:date_of_birth) { '22 Sep 1976'.to_date }
|
10
|
+
|
11
|
+
it "raises error if not born yet" do
|
12
|
+
expect { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '21 Sep 1976'.to_date) }.to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '22 Sep 1976'.to_date).should == 0 }
|
16
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '23 Sep 1976'.to_date).should == 0 }
|
17
|
+
|
18
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '21 Sep 1977'.to_date).should == 0 }
|
19
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '22 Sep 1977'.to_date).should == 1 }
|
20
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '23 Sep 1977'.to_date).should == 1 }
|
21
|
+
|
22
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '21 Sep 1978'.to_date).should == 1 }
|
23
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '22 Sep 1978'.to_date).should == 2 }
|
24
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '23 Sep 1978'.to_date).should == 2 }
|
25
|
+
|
26
|
+
it "uses current date when second argument missing" do
|
27
|
+
Timecop.freeze '22 Sep 2006'.to_date do
|
28
|
+
Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth).should == 30
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "leap year birthday" do
|
34
|
+
let(:date_of_birth) { '29 Feb 2004'.to_date }
|
35
|
+
|
36
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '1 Mar 2004'.to_date).should == 0 }
|
37
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '28 Feb 2005'.to_date).should == 0 }
|
38
|
+
specify { Years.age_where_leapling_legal_birthday_is_1_mar(date_of_birth, '1 Mar 2005'.to_date).should == 1 }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".age_where_leapling_legal_birthday_is_28_feb" do
|
43
|
+
let(:date_of_birth) { '29 Feb 2004'.to_date }
|
44
|
+
specify { Years.age_where_leapling_legal_birthday_is_28_feb(date_of_birth, '28 Feb 2005'.to_date).should == 1 }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".range" do
|
48
|
+
before do
|
49
|
+
Timecop.freeze '26 Jan 2012'.to_date
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
Timecop.return
|
54
|
+
end
|
55
|
+
|
56
|
+
specify { Years.range(2010).should == '2010–2012' }
|
57
|
+
specify { Years.range(2011).should == '2011–2012' }
|
58
|
+
specify { Years.range(2012).should == '2012' }
|
59
|
+
|
60
|
+
it "raises error if range would be in future" do
|
61
|
+
expect { Years.range(2013) }.to raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
specify { Years.range(2011, 2011).should == '2011' }
|
65
|
+
specify { Years.range(2011, 2012).should == '2011–2012' }
|
66
|
+
specify { Years.range(2011, 2013).should == '2011–2013' }
|
67
|
+
specify { Years.range(2011, 2014).should == '2011–2014' }
|
68
|
+
|
69
|
+
it "raises error if range is wrong way round" do
|
70
|
+
expect { Years.range(2013, 2011) }.to raise_error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/years.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 'years/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "years"
|
8
|
+
spec.version = Years::VERSION
|
9
|
+
spec.authors = ["Nigel Lowry"]
|
10
|
+
spec.email = ["nigel-lowry@ultra.eclipse.co.uk"]
|
11
|
+
spec.summary = %q{Small gem for showing year ranges.}
|
12
|
+
spec.description = %q{Small gem to create year ranges for copyright statements in Web pages.}
|
13
|
+
spec.homepage = ""
|
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_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "timecop"
|
25
|
+
spec.add_development_dependency "activesupport"
|
26
|
+
spec.add_development_dependency "yard"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: years
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nigel Lowry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
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: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Small gem to create year ranges for copyright statements in Web pages.
|
98
|
+
email:
|
99
|
+
- nigel-lowry@ultra.eclipse.co.uk
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .ruby-gemset
|
107
|
+
- .ruby-version
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/years.rb
|
113
|
+
- lib/years/version.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/years_spec.rb
|
116
|
+
- years.gemspec
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.2.1
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Small gem for showing year ranges.
|
141
|
+
test_files:
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/years_spec.rb
|
144
|
+
has_rdoc:
|