weekday_calculator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/weekday_calculator.rb +27 -0
  2. metadata +55 -0
@@ -0,0 +1,27 @@
1
+ require 'time'
2
+ require 'active_support_date_conversion'
3
+
4
+ module WeekdayCalculator
5
+ # The nth weekday from date
6
+ def self.nth_weekday(nth, date)
7
+ date = date.to_date
8
+ if date.wday == 6
9
+ adjustment = 1
10
+ else
11
+ adjustment = (2 * ((date.wday + nth - 1).div(5)))
12
+ end
13
+ date + nth + adjustment
14
+ end
15
+
16
+ # Gives you every nth weekday from start to finish
17
+ def self.every_nth_weekday(nth, start, finish)
18
+ start, finish = start.to_date, finish.to_date
19
+ weekdays = []
20
+ while
21
+ start = next_weekday = nth_weekday(nth, start)
22
+ break if start > finish
23
+ weekdays << next_weekday
24
+ end
25
+ weekdays
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weekday_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Keene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-04 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: brandon@cmdrkeene.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/weekday_calculator.rb
26
+ has_rdoc: true
27
+ homepage: http://github.com/cmdrkeene/weekday_calculator
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: nth-weekday calculation and every nth weekday calculation
54
+ test_files: []
55
+