datet 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,9 +8,9 @@ GEM
8
8
  git (>= 1.2.5)
9
9
  rake
10
10
  rdoc
11
- json (1.7.6)
11
+ json (1.7.7)
12
12
  rake (10.0.3)
13
- rdoc (3.12)
13
+ rdoc (3.12.2)
14
14
  json (~> 1.4)
15
15
  rspec (2.8.0)
16
16
  rspec-core (~> 2.8.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.21
1
+ 0.0.22
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "datet"
8
- s.version = "0.0.21"
8
+ s.version = "0.0.22"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = "2013-01-01"
12
+ s.date = "2013-03-06"
13
13
  s.description = "A framework for handeling date- and time-related stuff in Ruby."
14
14
  s.email = "k@spernj.org"
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.homepage = "http://github.com/kaspernj/datet"
34
34
  s.licenses = ["MIT"]
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = "1.8.24"
36
+ s.rubygems_version = "1.8.25"
37
37
  s.summary = "A framework for handeling date- and time-related stuff in Ruby."
38
38
 
39
39
  if s.respond_to? :specification_version then
@@ -1605,4 +1605,22 @@ class Datet
1605
1605
  #Spawn object with the given random values.
1606
1606
  return Datet.new(year, month, day, hour, min, sec)
1607
1607
  end
1608
+
1609
+ #Returns the current day in the year.
1610
+ def day_in_year
1611
+ day = self.day
1612
+
1613
+ 1.upto(self.month - 1) do |month_no|
1614
+ day += Datet.days_in_month(self.year, month_no)
1615
+ end
1616
+
1617
+ return day
1618
+ end
1619
+
1620
+ #Returns the age in years calculated from the current time and back.
1621
+ def age_in_years(cur = Datet.new)
1622
+ years = (cur.year - self.year)
1623
+ years -= 1 if cur.day_in_year < self.day_in_year
1624
+ return years
1625
+ end
1608
1626
  end
@@ -547,4 +547,16 @@ describe "Datet" do
547
547
  raise "Expected day between 20 and 25 but got: '#{datet.day}'." if datet.day < 20 or datet.day > 25
548
548
  end
549
549
  end
550
+
551
+ it "should be able to calculate day in the year" do
552
+ datet = Datet.in("1985-01-06")
553
+ datet.day_in_year.should eql(6)
554
+ end
555
+
556
+ it "should be able to calculate age based on dates" do
557
+ datet = Datet.in("1985-06-17")
558
+ age = datet.age_in_years
559
+ expect = 27
560
+ raise "Expected #{expect} but got #{years}" if age != expect
561
+ end
550
562
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  segments:
112
112
  - 0
113
- hash: -3943183192918576653
113
+ hash: -4119752225823393758
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  none: false
116
116
  requirements:
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 1.8.24
122
+ rubygems_version: 1.8.25
123
123
  signing_key:
124
124
  specification_version: 3
125
125
  summary: A framework for handeling date- and time-related stuff in Ruby.