Class: RiCal::PropertyValue::Date
- Inherits:
-
RiCal::PropertyValue
- Object
- RiCal::PropertyValue
- RiCal::PropertyValue::Date
- Defined in:
- lib/ri_cal/property_value/date.rb
Overview
-
©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
RiCal::PropertyValue::CalAddress represents an icalendar Date property value which is defined in RFC 2445 section 4.3.4 p 34
Instance Attribute Summary
Attributes inherited from RiCal::PropertyValue
Class Method Summary collapse
-
.valid_string?(string) ⇒ Boolean
:nodoc:.
Instance Method Summary collapse
-
#+(duration) ⇒ Object
Return the sum of the receiver and duration.
-
#-(other) ⇒ Object
Return the difference between the receiver and other.
-
#add_date_times_to(required_timezones) ⇒ Object
:nodoc:.
-
#advance(options) ⇒ Object
:nodoc:.
-
#change(options) ⇒ Object
:nodoc:.
-
#day ⇒ Object
Returns the day of the month.
- #for_occurrence(occurrence) ⇒ Object
-
#for_parent(parent) ⇒ Object
:nodoc:.
-
#method_missing(selector, *args) ⇒ Object
Delegate unknown messages to the wrappered Date instance.
-
#month ⇒ Object
Returns the month of the year (1..12).
-
#occurrence_period(default_duration) ⇒ Object
TODO: consider if this should be a period rather than a hash.
-
#ruby_value ⇒ Object
(also: #to_ri_cal_ruby_value)
Returns the ruby representation a ::Date.
- #start_of_day? ⇒ Boolean
- #subtract_from_date_time_value(date_time) ⇒ Object
- #to_finish_time ⇒ Object
- #to_floating_date_time_property ⇒ Object
-
#to_ri_cal_date_or_date_time_value ⇒ Object
Return the “Natural’ property value for the date_property, in this case the date property itself.”.
-
#to_ri_cal_date_time_value ⇒ Object
Return an instance of RiCal::PropertyValue::DateTime representing the start of this date.
-
#to_ri_cal_date_value(timezone_finder = nil) ⇒ Object
Return this date property.
- #to_zulu_occurrence_range_finish_time ⇒ Object
- #to_zulu_occurrence_range_start_time ⇒ Object
-
#tzid ⇒ Object
:nodoc:.
-
#tzid=(val) ⇒ Object
Nop to allow occurrence list to try to set it.
-
#value ⇒ Object
Returns the value of the reciever as an RFC 2445 iCalendar string.
-
#value=(val) ⇒ Object
Set the value of the property to val.
-
#visible_params ⇒ Object
:nodoc:.
-
#year ⇒ Object
Returns the year (including the century).
Methods inherited from RiCal::PropertyValue
#==, convert, date_or_date_time, date_or_date_time_or_period, #default_tzid, #enumerator, #equality_value, #find_timezone, if_valid_string, #initialize, #parms_string, #to_options_hash, #to_ri_cal_property_value, #to_s, #tz_info_source?, #validate_value
Constructor Details
This class inherits a constructor from RiCal::PropertyValue
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(selector, *args) ⇒ Object
Delegate unknown messages to the wrappered Date instance. TODO: Is this really necessary?
141 142 143 |
# File 'lib/ri_cal/property_value/date.rb', line 141 def method_missing(selector, *args) #:nodoc: @date_time_value.send(selector, *args) end |
Class Method Details
.valid_string?(string) ⇒ Boolean
:nodoc:
11 12 13 |
# File 'lib/ri_cal/property_value/date.rb', line 11 def self.valid_string?(string) #:nodoc: string =~ /^\d{8}$/ end |
Instance Method Details
#+(duration) ⇒ Object
Return the sum of the receiver and duration
The parameter other duration should be a RiCal::PropertyValue::Duration
The result will be an RiCal::PropertyValue::DateTime
135 136 137 |
# File 'lib/ri_cal/property_value/date.rb', line 135 def +(duration) duration.add_to_date_time_value(to_ri_cal_date_time_value) end |
#-(other) ⇒ Object
Return the difference between the receiver and other
The parameter other should be either a RiCal::PropertyValue::Duration or a RiCal::PropertyValue::DateTime
If other is a Duration, the result will be a DateTime, if it is a DateTime the result will be a Duration
122 123 124 |
# File 'lib/ri_cal/property_value/date.rb', line 122 def -(other) other.subtract_from_date_time_value(to_ri_cal_date_time_value) end |
#add_date_times_to(required_timezones) ⇒ Object
:nodoc:
113 114 115 |
# File 'lib/ri_cal/property_value/date.rb', line 113 def add_date_times_to(required_timezones) #:nodoc: # Do nothing since dates don't have a timezone end |
#advance(options) ⇒ Object
:nodoc:
105 106 107 |
# File 'lib/ri_cal/property_value/date.rb', line 105 def advance() #:nodoc: PropertyValue::Date.new(timezone_finder, :value => @date_time_value.advance(), :params =>(params ? params.dup : nil) ) end |
#change(options) ⇒ Object
:nodoc:
109 110 111 |
# File 'lib/ri_cal/property_value/date.rb', line 109 def change() #:nodoc: PropertyValue::Date.new(timezone_finder,:value => @date_time_value.change(), :params => (params ? params.dup : nil) ) end |
#day ⇒ Object
Returns the day of the month
68 69 70 |
# File 'lib/ri_cal/property_value/date.rb', line 68 def day @date_time_value.day end |
#for_occurrence(occurrence) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/ri_cal/property_value/date.rb', line 171 def for_occurrence(occurrence) if occurrence.start_of_day? occurrence.to_ri_cal_date_value(timezone_finder) else occurrence.for_parent(timezone_finder) end end |
#for_parent(parent) ⇒ Object
:nodoc:
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ri_cal/property_value/date.rb', line 94 def for_parent(parent) #:nodoc: if timezone_finder.nil? @timezone_finder = parent self elsif parent == timezone_finder self else Date.new(parent, :value => @date_time_value) end end |
#month ⇒ Object
Returns the month of the year (1..12)
63 64 65 |
# File 'lib/ri_cal/property_value/date.rb', line 63 def month @date_time_value.month end |
#occurrence_period(default_duration) ⇒ Object
TODO: consider if this should be a period rather than a hash
146 147 148 149 |
# File 'lib/ri_cal/property_value/date.rb', line 146 def occurrence_period(default_duration) #:nodoc: date_time = self.to_ri_cal_date_time_value RiCal::OccurrencePeriod.new(date_time, date_time.advance(:hours => 24, :seconds => -1)) end |
#ruby_value ⇒ Object Also known as: to_ri_cal_ruby_value
Returns the ruby representation a ::Date
73 74 75 |
# File 'lib/ri_cal/property_value/date.rb', line 73 def ruby_value @date_time_value.date end |
#start_of_day? ⇒ Boolean
151 152 153 |
# File 'lib/ri_cal/property_value/date.rb', line 151 def start_of_day? true end |
#subtract_from_date_time_value(date_time) ⇒ Object
126 127 128 |
# File 'lib/ri_cal/property_value/date.rb', line 126 def subtract_from_date_time_value(date_time) to_ri_cal_date_time_value.subtract_from_date_time_value(date_time) end |
#to_finish_time ⇒ Object
167 168 169 |
# File 'lib/ri_cal/property_value/date.rb', line 167 def to_finish_time to_ri_cal_date_time_value.end_of_day.to_datetime end |
#to_floating_date_time_property ⇒ Object
155 156 157 |
# File 'lib/ri_cal/property_value/date.rb', line 155 def to_floating_date_time_property PropertyValue::DateTime.new(timezone_finder, :value => @date_time_value.ical_str) end |
#to_ri_cal_date_or_date_time_value ⇒ Object
Return the “Natural’ property value for the date_property, in this case the date property itself.”
90 91 92 |
# File 'lib/ri_cal/property_value/date.rb', line 90 def to_ri_cal_date_or_date_time_value self end |
#to_ri_cal_date_time_value ⇒ Object
Return an instance of RiCal::PropertyValue::DateTime representing the start of this date
80 81 82 |
# File 'lib/ri_cal/property_value/date.rb', line 80 def to_ri_cal_date_time_value PropertyValue::DateTime.new(timezone_finder, :value => @date_time_value) end |
#to_ri_cal_date_value(timezone_finder = nil) ⇒ Object
Return this date property
85 86 87 |
# File 'lib/ri_cal/property_value/date.rb', line 85 def to_ri_cal_date_value(timezone_finder = nil) self end |
#to_zulu_occurrence_range_finish_time ⇒ Object
163 164 165 |
# File 'lib/ri_cal/property_value/date.rb', line 163 def to_zulu_occurrence_range_finish_time to_ri_cal_date_time_value.end_of_day.to_zulu_occurrence_range_finish_time end |
#to_zulu_occurrence_range_start_time ⇒ Object
159 160 161 |
# File 'lib/ri_cal/property_value/date.rb', line 159 def to_zulu_occurrence_range_start_time to_floating_date_time_property.to_zulu_occurrence_range_start_time end |
#tzid ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/ri_cal/property_value/date.rb', line 49 def tzid #:nodoc: nil end |
#tzid=(val) ⇒ Object
Nop to allow occurrence list to try to set it
46 47 |
# File 'lib/ri_cal/property_value/date.rb', line 46 def tzid=(val)#:nodoc: end |
#value ⇒ Object
Returns the value of the reciever as an RFC 2445 iCalendar string
16 17 18 19 20 21 22 |
# File 'lib/ri_cal/property_value/date.rb', line 16 def value if @date_time_value @date_time_value.ical_date_str else nil end end |
#value=(val) ⇒ Object
Set the value of the property to val
val may be either:
-
A string which can be parsed as a DateTime
-
A Time instance
-
A Date instance
-
A DateTime instance
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ri_cal/property_value/date.rb', line 32 def value=(val) case val when nil @date_time_value = nil when String @date_time_value = FastDateTime.from_date_time(::DateTime.parse(::DateTime.parse(val).strftime("%Y%m%d"))) when ::Time, ::Date, ::DateTime @date_time_value = FastDateTime.from_date_time(::DateTime.parse(val.strftime("%Y%m%d"))) when FastDateTime @date_time_value = val end end |
#visible_params ⇒ Object
:nodoc:
53 54 55 |
# File 'lib/ri_cal/property_value/date.rb', line 53 def visible_params #:nodoc: {"VALUE" => "DATE"}.merge(params) end |
#year ⇒ Object
Returns the year (including the century)
58 59 60 |
# File 'lib/ri_cal/property_value/date.rb', line 58 def year @date_time_value.year end |