nextday 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,15 +8,30 @@ Nextday only checks for English public holidays at the moment, I aim to extend i
8
8
 
9
9
  ## Usage
10
10
 
11
+ ### Find the next working day
11
12
  ```ruby
12
13
  Date.today.next_working_day
13
14
  DateTime.today.next_working_day
14
15
  Time.now.next_working_day
15
16
  ```
16
17
 
18
+ ### Find the previous working day
19
+ ```ruby
20
+ Date.today.previous_working_day
21
+ DateTime.today.previous_working_day
22
+ Time.now.previous_working_day
23
+ ```
24
+
25
+ ### Is the current day a working day?
26
+ ```ruby
27
+ Date.today.working_day?
28
+ DateTime.today.working_day?
29
+ Time.now.working_day?
30
+ ```
31
+
17
32
  ## Installation
18
33
 
19
- To use with bundler just add nextday to your gem file.
34
+ To use with bundler add nextday to your gem file.
20
35
 
21
36
  ```ruby
22
37
  gem 'nextday'
@@ -41,6 +41,21 @@ module Nextday
41
41
  next_day
42
42
  end
43
43
 
44
+ ##
45
+ # The previous working day before the current date
46
+ #
47
+ # @return [Date] Previous Working Day
48
+ def previous_working_day
49
+ previous_day = to_date - 1
50
+
51
+ # keep going until the next day is a working day
52
+ while !previous_day.working_day?
53
+ previous_day = previous_day - 1
54
+ end
55
+
56
+ previous_day
57
+ end
58
+
44
59
  ##
45
60
  # Is the current date a working day?
46
61
  #
@@ -1,3 +1,3 @@
1
1
  module Nextday
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -90,4 +90,31 @@ describe Date do
90
90
  }
91
91
  end
92
92
  end
93
+
94
+ describe "#previous_working_day" do
95
+
96
+ subject {Date.today.previous_working_day}
97
+
98
+ it {should be_kind_of(Date)}
99
+ it {should_not eql(Date.today)}
100
+ it {should be_a_working_day }
101
+
102
+ describe "on a saturday" do
103
+ it {
104
+ saturdays.each { |date| date.previous_working_day.should be_a_working_day }
105
+ }
106
+ end
107
+
108
+ describe "on a sunday" do
109
+ it {
110
+ sundays.each { |date| date.previous_working_day.should be_a_working_day }
111
+ }
112
+ end
113
+
114
+ describe "on a public holiday" do
115
+ it {
116
+ Nextday::Holidays.dates.each { |date| date.previous_working_day.should be_a_working_day }
117
+ }
118
+ end
119
+ end
93
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nextday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-02 00:00:00.000000000 Z
12
+ date: 2012-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152939220 !ruby/object:Gem::Requirement
16
+ requirement: &70211612224480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.6.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152939220
24
+ version_requirements: *70211612224480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &2152938800 !ruby/object:Gem::Requirement
27
+ requirement: &70211612224060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152938800
35
+ version_requirements: *70211612224060
36
36
  description: ! "\n Finds the Next Working Day even if holidays are in the way.\n
37
37
  \ Extends Date with a .next_working_day instance method.\n "
38
38
  email:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project: nextday
85
- rubygems_version: 1.8.6
85
+ rubygems_version: 1.8.15
86
86
  signing_key:
87
87
  specification_version: 3
88
88
  summary: Finds the Next Working Day even if holidays are in the way.