sixarm_ruby_date_age 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/INSTALL.txt +32 -0
- data/LICENSE.txt +12 -0
- data/README.rdoc +24 -0
- data/Rakefile +8 -0
- data/lib/sixarm_ruby_date_age.rb +93 -0
- data/test/sixarm_ruby_date_age_test.rb +43 -0
- data.tar.gz.sig +0 -0
- metadata +82 -0
- metadata.gz.sig +0 -0
data/.gemtest
ADDED
File without changes
|
data/INSTALL.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
= SixArm.com Ruby Gem Install
|
3
|
+
|
4
|
+
|
5
|
+
First-time users: add our gem certificate and source.
|
6
|
+
When you do this once, it works for all our gems.
|
7
|
+
|
8
|
+
sudo wget http://sixarm.com/sixarm.pem
|
9
|
+
sudo gem cert --add sixarm.pem
|
10
|
+
sudo gem sources --add http://sixarm.com
|
11
|
+
|
12
|
+
Install the gem with advanced options.
|
13
|
+
|
14
|
+
sudo gem install sixarm_ruby_date_age --test --trust-policy HighSecurity
|
15
|
+
|
16
|
+
|
17
|
+
== Notes
|
18
|
+
|
19
|
+
Do you have any questions, comments, suggestions, or feedback?
|
20
|
+
Let us know, we're happy to help. Our email is sixarm@sixarm.com
|
21
|
+
|
22
|
+
Do you want to create your own high security gems?
|
23
|
+
Learn how at http://www.rubygems.org/read/chapter/21
|
24
|
+
|
25
|
+
To see your current gem certificate list:
|
26
|
+
|
27
|
+
sudo gem cert --list
|
28
|
+
|
29
|
+
Our cert looks like this:
|
30
|
+
|
31
|
+
/C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
|
32
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
You may choose any of these licenses:
|
4
|
+
|
5
|
+
- CreativeCommons License, Non-commercial Share Alike
|
6
|
+
- LGPL, GNU Lesser General Public License
|
7
|
+
- MIT License
|
8
|
+
- Ruby License
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
11
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
12
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
= SixArm.com » Ruby » Date #age_in_years and #age_in_days methods
|
4
|
+
|
5
|
+
Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
|
6
|
+
Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
|
7
|
+
License:: See LICENSE.txt file
|
8
|
+
|
9
|
+
Date extensions to calculate an age in days and years.
|
10
|
+
|
11
|
+
@example
|
12
|
+
|
13
|
+
date=Date.new(1980,10,31)
|
14
|
+
date.age_in_days => 11124
|
15
|
+
date.age_in_years => 31
|
16
|
+
|
17
|
+
@example of custom dates
|
18
|
+
|
19
|
+
date=Date.new(1980,10,31)
|
20
|
+
new_years_eve=(2011,12,31)
|
21
|
+
date.age_in_days_on(new_years_eve) => 11383
|
22
|
+
date.age_in_years_on(new_years_eve) => 31
|
23
|
+
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin rdoc
|
4
|
+
|
5
|
+
= SixArm.com » Ruby » Date #age_in_years and #age_in_days methods
|
6
|
+
|
7
|
+
Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
|
8
|
+
Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
|
9
|
+
License:: See LICENSE.txt file
|
10
|
+
|
11
|
+
Date extensions to calculate an age in days and years.
|
12
|
+
|
13
|
+
@example
|
14
|
+
|
15
|
+
date=Date.new(1980,10,31)
|
16
|
+
date.age_in_days => 11124
|
17
|
+
date.age_in_years => 31
|
18
|
+
|
19
|
+
@example of custom dates
|
20
|
+
|
21
|
+
date=Date.new(1980,10,31)
|
22
|
+
new_years_eve=(2011,12,31)
|
23
|
+
date.age_in_days_on(new_years_eve) => 11383
|
24
|
+
date.age_in_years_on(new_years_eve) => 31
|
25
|
+
|
26
|
+
|
27
|
+
=end
|
28
|
+
|
29
|
+
|
30
|
+
class Date
|
31
|
+
|
32
|
+
|
33
|
+
# @return [Integer] the age in days for a given date.
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
#
|
37
|
+
# date=Date.new(1980,10,31)
|
38
|
+
# date.age_in_days => 11124
|
39
|
+
#
|
40
|
+
# @example of custom dates
|
41
|
+
#
|
42
|
+
# date=Date.new(1980,10,31)
|
43
|
+
#
|
44
|
+
# valentines = Date.new(2011,02,14)
|
45
|
+
# date.age_in_days(valentines) => 11063
|
46
|
+
#
|
47
|
+
# halloween = Date.new(2011,10,31)
|
48
|
+
# date.age_in_days(halloween) => 11322
|
49
|
+
#
|
50
|
+
# new_years_eve = Date.new(2011,12,31)
|
51
|
+
# date.age_in_days(new_years_eve) => 11383
|
52
|
+
|
53
|
+
def age_in_days(compare_date=Date.today)
|
54
|
+
(compare_date.is_a? Date) or raise ArgumentError, "compare_date must be a date"
|
55
|
+
(compare_date-self).to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
alias :age_in_days_on :age_in_days
|
59
|
+
|
60
|
+
|
61
|
+
# @return [Integer] the age in years for a given date.
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
#
|
65
|
+
# date=Date.new(1980,10,31)
|
66
|
+
# date.age_in_years => 30
|
67
|
+
#
|
68
|
+
# @example of custom dates
|
69
|
+
#
|
70
|
+
# date=Date.new(1980,10,31)
|
71
|
+
#
|
72
|
+
# valentines = Date.new(2011,02,14)
|
73
|
+
# date.age_in_years_on(valentines) => 30 # before the birthday
|
74
|
+
#
|
75
|
+
# halloween = Date.new(2011,10,31)
|
76
|
+
# date.age_in_years_on(halloween) => 31 # on the birthday is one year older
|
77
|
+
#
|
78
|
+
# new_years_eve = Date.new(2011,12,31)
|
79
|
+
# date.age_years(new_years_eve) => 31 # after the birthday is one year older
|
80
|
+
|
81
|
+
def age_in_years(compare_date=Date.today)
|
82
|
+
(compare_date.is_a? Date) or raise ArgumentError, "compare_date must be a date"
|
83
|
+
age=compare_date.year-year
|
84
|
+
compare_month = compare_date.month
|
85
|
+
age-=1 if compare_month < month or (compare_month==month and compare_date.day < day)
|
86
|
+
age
|
87
|
+
end
|
88
|
+
|
89
|
+
alias :age_in_years_on :age_in_years
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
require 'test/unit'
|
5
|
+
require 'sixarm_ruby_date_age'
|
6
|
+
|
7
|
+
class DateAgeTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
# for test_age_years and test_age_days
|
10
|
+
BIRTHDATE = Date.new(1980,10,31)
|
11
|
+
VALENTINES = Date.new(2011,02,14)
|
12
|
+
HALLOWEEN = Date.new(2011,10,31)
|
13
|
+
NEW_YEARS_EVE = Date.new(2011,12,31)
|
14
|
+
|
15
|
+
def test_age_in_days
|
16
|
+
assert_equal(11063,BIRTHDATE.age_in_days(VALENTINES), '< birthday')
|
17
|
+
assert_equal(11322,BIRTHDATE.age_in_days(HALLOWEEN), '= birthday')
|
18
|
+
assert_equal(11383,BIRTHDATE.age_in_days(NEW_YEARS_EVE), '> birthday')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_age_in_days_with_non_date
|
22
|
+
assert_raise(ArgumentError){ BIRTHDATE.age_in_days('') }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_age_in_days_alias
|
26
|
+
assert_equal(BIRTHDATE.age_in_days(VALENTINES), BIRTHDATE.age_in_days_on(VALENTINES))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_age_in_years
|
30
|
+
assert_equal(30,BIRTHDATE.age_in_years(VALENTINES), '< birthday')
|
31
|
+
assert_equal(31,BIRTHDATE.age_in_years(HALLOWEEN), '= birthday')
|
32
|
+
assert_equal(31,BIRTHDATE.age_in_years(NEW_YEARS_EVE), '> birthday')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_age_in_years_with_non_date
|
36
|
+
assert_raise(ArgumentError){ BIRTHDATE.age_in_years('') }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_age_in_years_alias
|
40
|
+
assert_equal(BIRTHDATE.age_in_years(VALENTINES), BIRTHDATE.age_in_years_on(VALENTINES))
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_date_age
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SixArm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- |
|
13
|
+
-----BEGIN CERTIFICATE-----
|
14
|
+
MIIDBDCCAm2gAwIBAgIJAKPwEETU5bHoMA0GCSqGSIb3DQEBBQUAMGAxCzAJBgNV
|
15
|
+
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
|
16
|
+
c2NvMQ8wDQYDVQQKEwZTaXhBcm0xEzARBgNVBAMTCnNpeGFybS5jb20wHhcNMTAx
|
17
|
+
MjEzMjMyNzEzWhcNMTMwOTA4MjMyNzEzWjBgMQswCQYDVQQGEwJVUzETMBEGA1UE
|
18
|
+
CBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA1UEChMG
|
19
|
+
U2l4QXJtMRMwEQYDVQQDEwpzaXhhcm0uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GN
|
20
|
+
ADCBiQKBgQC94mD9JDwBsunsOI0VR3CXXbOWg9cWaWciwFyJNFiM7A9I8KPLfXUw
|
21
|
+
QC4czUe5ZuG4WHvinrWhkrCK+1dWBqoEClxdF/FoKO5a+tonGCjjmfy81JmFjjyx
|
22
|
+
eTsjsHyvw+Qik9kpf9aj6+pnkNrVswgNHVea2o9yabbEiS6VSeJWoQIDAQABo4HF
|
23
|
+
MIHCMB0GA1UdDgQWBBQzPJtqmSgc53eDN7aSzDQwr9TALDCBkgYDVR0jBIGKMIGH
|
24
|
+
gBQzPJtqmSgc53eDN7aSzDQwr9TALKFkpGIwYDELMAkGA1UEBhMCVVMxEzARBgNV
|
25
|
+
BAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzANBgNVBAoT
|
26
|
+
BlNpeEFybTETMBEGA1UEAxMKc2l4YXJtLmNvbYIJAKPwEETU5bHoMAwGA1UdEwQF
|
27
|
+
MAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAooEexP/oPam1TP71SyuhxMb+uTrZbSQe
|
28
|
+
jVB+ExRwWadGwaNPUA56d39qwavwP+iu+3JpeonNMVvbWXF5naCX/dNFIeREHzER
|
29
|
+
ZDRQYMqru9TEMna6HD9zpcstF7vwThGovlOQ+3Y6plQ4nMzipXcZ9THqs65PIL0q
|
30
|
+
eabwpCbAopo=
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2011-04-16 00:00:00 -07:00
|
34
|
+
default_executable:
|
35
|
+
dependencies: []
|
36
|
+
|
37
|
+
description:
|
38
|
+
email: sixarm@sixarm.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gemtest
|
47
|
+
- Rakefile
|
48
|
+
- README.rdoc
|
49
|
+
- INSTALL.txt
|
50
|
+
- LICENSE.txt
|
51
|
+
- lib/sixarm_ruby_date_age.rb
|
52
|
+
- test/sixarm_ruby_date_age_test.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://sixarm.com/
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.6.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: "SixArm.com \xC2\xBB Ruby \xC2\xBB Date #age_in_days and #age_in_years methods"
|
81
|
+
test_files:
|
82
|
+
- test/sixarm_ruby_date_age_test.rb
|
metadata.gz.sig
ADDED
Binary file
|