Module: WeekOfMonth::Day
Instance Method Summary collapse
-
#all_non_week_days_of_month ⇒ Object
returns array of all non working days of the month Date.new(2014,12,1).all_non_week_days_of_month => [#<Date: 2014-12-28 ((2457020j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-27 ((2457019j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-21 ((2457013j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-20 ((2457012j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-14 ((2457006j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-13 ((2457005j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-07 ((2456999j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-06 ((2456998j,0s,0n),+0s,2299161j)>].
-
#all_working_days_of_month ⇒ Object
returns array of all working days of the month Date.new(2014,12,1).all_working_days_of_month => [#<Date: 2014-12-31 ((2457023j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-30 ((2457022j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-29 ((2457021j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-26 ((2457018j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-25 ((2457017j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-24 ((2457016j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-23 ((2457015j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-22 ((2457014j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-19 ((2457011j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-18 ((2457010j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-17 ((2457009j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-16 ((2457008j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-15 ((2457007j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-12 ((2457004j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-11 ((2457003j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-10 ((2457002j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-09 ((2457001j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-08 ((2457000j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-05 ((2456997j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-04 ((2456996j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-03 ((2456995j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-02 ((2456994j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-01 ((2456993j,0s,0n),+0s,2299161j)>].
-
#days_array ⇒ Array
gives array of days in month Date.new(2012,1,1).days_array => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31].
-
#first_working_day_of_the_month ⇒ Object
returns first working/business day of the month Date.new(2014,12,1).first_working_day_of_the_month => #<Date: 2014-12-01 ((2456993j,0s,0n),+0s,2299161j)>.
-
#last_business_day_of_month ⇒ Object
gives last working/business day of the month Date.new(2014,12,1).last_business_day_of_month => #<Date: 2014-12-31 ((2457023j,0s,0n),+0s,2299161j)>.
-
#name_of_week_day ⇒ String
Date.new(2012,11,1).name_of_week_day => ‘Thursday’.
Instance Method Details
#all_non_week_days_of_month ⇒ Object
returns array of all non working days of the month Date.new(2014,12,1).all_non_week_days_of_month
> [#<Date: 2014-12-28 ((2457020j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-27 ((2457019j,0s,0n),+0s,2299161j)>,
#<Date: 2014-12-21 ((2457013j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-20 ((2457012j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-14 ((2457006j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-13 ((2457005j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-07 ((2456999j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-06 ((2456998j,0s,0n),+0s,2299161j)>]
102 103 104 |
# File 'lib/modules/day.rb', line 102 def all_non_week_days_of_month end_of_month.downto(beginning_of_month).select(&:week_end?) end |
#all_working_days_of_month ⇒ Object
returns array of all working days of the month Date.new(2014,12,1).all_working_days_of_month
> [#<Date: 2014-12-31 ((2457023j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-30 ((2457022j,0s,0n),+0s,2299161j)>,
#<Date: 2014-12-29 ((2457021j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-26 ((2457018j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-25 ((2457017j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-24 ((2457016j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-23 ((2457015j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-22 ((2457014j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-19 ((2457011j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-18 ((2457010j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-17 ((2457009j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-16 ((2457008j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-15 ((2457007j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-12 ((2457004j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-11 ((2457003j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-10 ((2457002j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-09 ((2457001j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-08 ((2457000j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-05 ((2456997j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-04 ((2456996j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-03 ((2456995j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-02 ((2456994j,0s,0n),+0s,2299161j)>, #<Date: 2014-12-01 ((2456993j,0s,0n),+0s,2299161j)>]
92 93 94 |
# File 'lib/modules/day.rb', line 92 def all_working_days_of_month end_of_month.downto(beginning_of_month).select(&:working_day?) end |
#days_array ⇒ Array
gives array of days in month Date.new(2012,1,1).days_array
=> [ 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
31]
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/modules/day.rb', line 22 def days_array day = beginning_of_month.to_date.wday if WeekOfMonth.configuration.monday_active == true day = day.zero? ? 6 : day - 1 end array = [] array[day] = 1 (2..end_of_month.mday).each { |i| array << i } array end |
#first_working_day_of_the_month ⇒ Object
returns first working/business day of the month Date.new(2014,12,1).first_working_day_of_the_month
> #<Date: 2014-12-01 ((2456993j,0s,0n),+0s,2299161j)>
109 110 111 |
# File 'lib/modules/day.rb', line 109 def first_working_day_of_the_month beginning_of_month.upto(end_of_month).find(&:working_day?) end |
#last_business_day_of_month ⇒ Object
gives last working/business day of the month Date.new(2014,12,1).last_business_day_of_month
> #<Date: 2014-12-31 ((2457023j,0s,0n),+0s,2299161j)>
74 75 76 |
# File 'lib/modules/day.rb', line 74 def last_business_day_of_month all_working_days_of_month.first end |
#name_of_week_day ⇒ String
Date.new(2012,11,1).name_of_week_day
=> 'Thursday'
36 37 38 |
# File 'lib/modules/day.rb', line 36 def name_of_week_day self.class.new(year, month, day).strftime('%A') end |