Module: RiCal::PropertyValue::DateTime::TimeMachine
- Included in:
- RiCal::PropertyValue::DateTime
- Defined in:
- lib/ri_cal/property_value/date_time/time_machine.rb
Overview
Methods for DateTime which support getting values at different point in time.
Instance Method Summary collapse
-
#advance(options) ⇒ Object
:nodoc:.
-
#at_end_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the last day of the ISO year with weeks starting on wkst containing the receiver.
-
#at_start_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks starting on wkst containing the receiver.
-
#at_start_of_next_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks starting on wkst after the ISO year containing the receiver.
-
#at_start_of_week_with_wkst(wkst) ⇒ Object
Return a DATE-TIME property representing the receiver on a different day (if necessary) so that the result is the first day of the ISO week starting on the wkst day containing the receiver.
-
#change(options) ⇒ Object
:nodoc:.
-
#change_day(new_day) ⇒ Object
:nodoc:.
-
#change_hour(new_hour) ⇒ Object
:nodoc:.
-
#change_min(new_min) ⇒ Object
:nodoc:.
-
#change_month(new_month) ⇒ Object
:nodoc:.
-
#change_sec(new_sec) ⇒ Object
:nodoc:.
-
#change_year(new_year) ⇒ Object
:nodoc:.
-
#end_of_day ⇒ Object
Return a DATE_TIME value representing the last second of the day containing the receiver.
-
#end_of_hour ⇒ Object
Return a DATE_TIME value representing the last second of the hour containing the receiver.
-
#end_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the last second of the last day of the ISO year with weeks starting on wkst containing the receiver.
-
#end_of_minute ⇒ Object
Return a DATE_TIME value representing the last second of the minute containing the receiver.
-
#end_of_month ⇒ Object
Return a DATE_TIME value representing the last second of the month containing the receiver.
-
#end_of_week_with_wkst(wkst) ⇒ Object
Return a DATE_TIME value representing the last second of the ISO week starting with wkst containing the receiver.
-
#end_of_year ⇒ Object
Return a DATE_TIME value representing the last second of the month containing the receiver.
-
#in_month(month) ⇒ Object
Return a DATE-TIME representing the same time, on the same day of the month in month.
-
#in_week_starting?(date) ⇒ Boolean
Return a DATE-TIME property representing the receiver on a different day (if necessary) so that the result is within the 7 days starting with date.
-
#start_of_day ⇒ Object
Return a DATE_TIME value representing the first second of the day containing the receiver.
-
#start_of_hour ⇒ Object
Return a DATE_TIME value representing the first second of the hour containing the receiver.
-
#start_of_minute ⇒ Object
Return a DATE_TIME value representing the first second of the minute containing the receiver.
-
#start_of_month ⇒ Object
Return a DATE_TIME value representing the first second of the month containing the receiver.
-
#start_of_week_with_wkst(wkst) ⇒ Object
Return a Ruby Date representing the first day of the ISO week starting with wkst containing the receiver.
-
#start_of_year ⇒ Object
Return a DATE_TIME value representing the first second of the month containing the receiver.
Instance Method Details
#advance(options) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 7 def advance() # :nodoc: PropertyValue::DateTime.new(timezone_finder, :value => @date_time_value.advance(), :tzid => @tzid, :params =>(params ? params.dup : nil) ) end |
#at_end_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the last day of the ISO year with weeks starting on wkst containing the receiver
129 130 131 132 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 129 def at_end_of_iso_year(wkst) num_weeks = @date_time_value.iso_weeks_in_year(wkst) at_start_of_iso_year(wkst).advance(:weeks => (num_weeks - 1), :days => 6) end |
#at_start_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks starting on wkst containing the receiver
122 123 124 125 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 122 def at_start_of_iso_year(wkst) start_of_year = @date_time_value.iso_year_start(wkst) change(:year => start_of_year.year, :month => start_of_year.month, :day => start_of_year.day) end |
#at_start_of_next_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the same time on the first day of the ISO year with weeks starting on wkst after the ISO year containing the receiver
136 137 138 139 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 136 def at_start_of_next_iso_year(wkst) num_weeks = @date_time_value.iso_weeks_in_year(wkst) at_start_of_iso_year(wkst).advance(:weeks => num_weeks) end |
#at_start_of_week_with_wkst(wkst) ⇒ Object
Return a DATE-TIME property representing the receiver on a different day (if necessary) so that the result is the first day of the ISO week starting on the wkst day containing the receiver.
56 57 58 59 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 56 def at_start_of_week_with_wkst(wkst) date = @date_time_value.start_of_week_with_wkst(wkst) change(:year => date.year, :month => date.month, :day => date.day) end |
#change(options) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 15 def change() # :nodoc: PropertyValue::DateTime.new(timezone_finder, :value => @date_time_value.change(), :tzid => @tzid, :params => (params ? params.dup : nil) ) end |
#change_day(new_day) ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 35 def change_day(new_day) #:nodoc: change(:day => new_day) end |
#change_hour(new_hour) ⇒ Object
:nodoc:
31 32 33 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 31 def change_hour(new_hour) #:nodoc: change(:hour => new_hour) end |
#change_min(new_min) ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 27 def change_min(new_min) #:nodoc: change(:min => new_min) end |
#change_month(new_month) ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 39 def change_month(new_month) #:nodoc: change(:month => new_month) end |
#change_sec(new_sec) ⇒ Object
:nodoc:
23 24 25 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 23 def change_sec(new_sec) #:nodoc: change(:sec => new_sec) end |
#change_year(new_year) ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 43 def change_year(new_year) #:nodoc: change(:year => new_year) end |
#end_of_day ⇒ Object
Return a DATE_TIME value representing the last second of the day containing the receiver
86 87 88 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 86 def end_of_day change(:hour => 23, :min => 59, :sec => 59) end |
#end_of_hour ⇒ Object
Return a DATE_TIME value representing the last second of the hour containing the receiver
76 77 78 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 76 def end_of_hour change(:min => 59, :sec => 59) end |
#end_of_iso_year(wkst) ⇒ Object
Return a DATE_TIME value representing the last second of the last day of the ISO year with weeks starting on wkst containing the receiver
143 144 145 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 143 def end_of_iso_year(wkst) at_end_of_iso_year(wkst).end_of_day end |
#end_of_minute ⇒ Object
Return a DATE_TIME value representing the last second of the minute containing the receiver
66 67 68 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 66 def end_of_minute change(:sec => 59) end |
#end_of_month ⇒ Object
Return a DATE_TIME value representing the last second of the month containing the receiver
106 107 108 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 106 def end_of_month change(:day => days_in_month, :hour => 23, :min => 59, :sec => 59) end |
#end_of_week_with_wkst(wkst) ⇒ Object
Return a DATE_TIME value representing the last second of the ISO week starting with wkst containing the receiver
96 97 98 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 96 def end_of_week_with_wkst(wkst) date = at_start_of_week_with_wkst(wkst).advance(:days => 6).end_of_day end |
#end_of_year ⇒ Object
Return a DATE_TIME value representing the last second of the month containing the receiver
116 117 118 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 116 def end_of_year change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59) end |
#in_month(month) ⇒ Object
Return a DATE-TIME representing the same time, on the same day of the month in month. If the month of the receiver has more days than the target month the last day of the target month will be used.
150 151 152 153 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 150 def in_month(month) first = change(:day => 1, :month => month) first.change(:day => [first.days_in_month, day].min) end |
#in_week_starting?(date) ⇒ Boolean
Return a DATE-TIME property representing the receiver on a different day (if necessary) so that the result is within the 7 days starting with date
49 50 51 52 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 49 def in_week_starting?(date) wkst_jd = date.jd @date_time_value.jd.between?(wkst_jd, wkst_jd + 6) end |
#start_of_day ⇒ Object
Return a DATE_TIME value representing the first second of the day containing the receiver
81 82 83 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 81 def start_of_day change(:hour => 0, :min => 0, :sec => 0) end |
#start_of_hour ⇒ Object
Return a DATE_TIME value representing the first second of the hour containing the receiver
71 72 73 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 71 def start_of_hour change(:min => 0, :sec => 0) end |
#start_of_minute ⇒ Object
Return a DATE_TIME value representing the first second of the minute containing the receiver
61 62 63 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 61 def start_of_minute change(:sec => 0) end |
#start_of_month ⇒ Object
Return a DATE_TIME value representing the first second of the month containing the receiver
101 102 103 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 101 def start_of_month change(:day => 1, :hour => 0, :min => 0, :sec => 0) end |
#start_of_week_with_wkst(wkst) ⇒ Object
Return a Ruby Date representing the first day of the ISO week starting with wkst containing the receiver
91 92 93 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 91 def start_of_week_with_wkst(wkst) @date_time_value.start_of_week_with_wkst(wkst) end |
#start_of_year ⇒ Object
Return a DATE_TIME value representing the first second of the month containing the receiver
111 112 113 |
# File 'lib/ri_cal/property_value/date_time/time_machine.rb', line 111 def start_of_year change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0) end |