Class: Suprdate::Day
Constant Summary collapse
- STRFTIME_STR =
'%Y-%m-%d'
Instance Attribute Summary collapse
-
#month ⇒ Object
readonly
Returns the value of attribute month.
Attributes inherited from Unit
Instance Method Summary collapse
-
#+(increase) ⇒ Object
Return a new day incremented by an integer.
-
#-(decrease) ⇒ Object
Return a new day decremented by an integer.
- #<=>(operand) ⇒ Object
-
#date ⇒ Object
This day as a Ruby Date object.
-
#datetime ⇒ Object
This day as a Ruby DateTime object.
-
#day ⇒ Object
Polymorphic feature; guarantees you a Suprdate::Day.
-
#days ⇒ Object
Polymorphic feature; guarantees you a list of Suprdate::Day.
- #inspect ⇒ Object
-
#leap? ⇒ Boolean
Whether this day is a leap day or, in other words, February 29th.
-
#new_from_date(date) ⇒ Object
:nodoc:.
-
#of_week_as_i ⇒ Object
Day of the week as an integer.
-
#of_week_as_s ⇒ Object
Day of the week as a string.
-
#of_week_as_sym ⇒ Object
Day of the week as a symbol.
-
#of_year ⇒ Object
Day of the year.
-
#parts ⇒ Object
:nodoc:.
-
#since(operand) ⇒ Object
The number of days since parameter#day.
-
#succ ⇒ Object
Next successive day.
-
#time ⇒ Object
This day as a Ruby Time object.
-
#until(operand) ⇒ Object
The number of days until parameter#day.
-
#weekday_occurrence_this_month ⇒ Object
If this day is the first Monday of the month this method returns 1.
- #year ⇒ Object
Methods inherited from Unit
<=>, #==, #hash, #new, significance, #to_s
Methods included from Utility::CleanConstantName
#name_plural, #name_singular, #to_sym
Instance Attribute Details
#month ⇒ Object (readonly)
Returns the value of attribute month.
6 7 8 |
# File 'lib/suprdate/day.rb', line 6 def month @month end |
Instance Method Details
#+(increase) ⇒ Object
Return a new day incremented by an integer.
57 |
# File 'lib/suprdate/day.rb', line 57 def +(increase) new_from_date(date + increase) end |
#-(decrease) ⇒ Object
Return a new day decremented by an integer.
60 |
# File 'lib/suprdate/day.rb', line 60 def -(decrease) new_from_date(date - decrease) end |
#<=>(operand) ⇒ Object
68 69 70 71 |
# File 'lib/suprdate/day.rb', line 68 def <=>(operand) return -1 if operand == Infinity date <=> operand.day.date end |
#date ⇒ Object
This day as a Ruby Date object.
27 |
# File 'lib/suprdate/day.rb', line 27 def date() Date.new(*parts) end |
#datetime ⇒ Object
This day as a Ruby DateTime object.
30 |
# File 'lib/suprdate/day.rb', line 30 def datetime() DateTime.new(*parts) end |
#day ⇒ Object
Polymorphic feature; guarantees you a Suprdate::Day
36 |
# File 'lib/suprdate/day.rb', line 36 def day() self end |
#days ⇒ Object
Polymorphic feature; guarantees you a list of Suprdate::Day
33 |
# File 'lib/suprdate/day.rb', line 33 def days() [self] end |
#inspect ⇒ Object
20 |
# File 'lib/suprdate/day.rb', line 20 def inspect() "#@month-#{@value.to_s.rjust(2, '0')}" end |
#leap? ⇒ Boolean
Whether this day is a leap day or, in other words, February 29th.
51 |
# File 'lib/suprdate/day.rb', line 51 def leap?() value == 29 && @month.value == 2 end |
#new_from_date(date) ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/suprdate/day.rb', line 88 def new_from_date(date) # :nodoc: new(@month.new(year.new(date.year), date.month), date.day) end |
#of_week_as_i ⇒ Object
Day of the week as an integer. Presently Sunday is 1, Monday is 2 etc.
45 |
# File 'lib/suprdate/day.rb', line 45 def of_week_as_i() date.wday + 1 end |
#of_week_as_s ⇒ Object
Day of the week as a string. (See Suprdate::WEEKDAYS_AS_STR)
42 |
# File 'lib/suprdate/day.rb', line 42 def of_week_as_s() WEEKDAYS_AS_STR[of_week_as_i] end |
#of_week_as_sym ⇒ Object
Day of the week as a symbol. (See Suprdate::WEEKDAYS_AS_SYM)
39 |
# File 'lib/suprdate/day.rb', line 39 def of_week_as_sym() WEEKDAYS_AS_SYM[of_week_as_i] end |
#of_year ⇒ Object
Day of the year. January 1st is 1.
48 |
# File 'lib/suprdate/day.rb', line 48 def of_year() (date - Date.new(year.value, 1, 1)).numerator + 1 end |
#parts ⇒ Object
:nodoc:
86 |
# File 'lib/suprdate/day.rb', line 86 def parts() [year.value, @month.value, value] end |
#since(operand) ⇒ Object
The number of days since parameter#day.
63 |
# File 'lib/suprdate/day.rb', line 63 def since(operand) (date - operand.day.date).numerator end |
#succ ⇒ Object
Next successive day.
54 |
# File 'lib/suprdate/day.rb', line 54 def succ() self + 1 end |
#time ⇒ Object
This day as a Ruby Time object.
24 |
# File 'lib/suprdate/day.rb', line 24 def time() Time.mktime(*parts) end |
#until(operand) ⇒ Object
The number of days until parameter#day.
66 |
# File 'lib/suprdate/day.rb', line 66 def until(operand) (operand.day.date - date).numerator end |
#weekday_occurrence_this_month ⇒ Object
If this day is the first Monday of the month this method returns 1. If this day is the second Monday of the month this method returns 2. Works for all days.
76 77 78 79 80 81 82 |
# File 'lib/suprdate/day.rb', line 76 def weekday_occurrence_this_month w = of_week_as_i w_days_this_month = @month.days[0..value - 1].select do |day| day.of_week_as_i == w end ORDINALS[w_days_this_month.nitems] end |
#year ⇒ Object
21 |
# File 'lib/suprdate/day.rb', line 21 def year() @month.year end |