Module: RiCal::PropertyValue::DateTime::TimezoneSupport
- Included in:
- RiCal::PropertyValue::DateTime
- Defined in:
- lib/ri_cal/property_value/date_time/timezone_support.rb
Overview
-
©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
Time zone related methods for DateTime
Instance Method Summary collapse
-
#find_timezone ⇒ Object
:nodoc:.
-
#has_local_timezone? ⇒ Boolean
Determine if the receiver has a local time zone, i.e.
-
#in_time_zone(new_zone) ⇒ Object
Returns the simultaneous time in the specified zone.
-
#rational_tz_offset ⇒ Object
:nodoc:.
-
#timezone ⇒ Object
:nodoc:.
-
#tzid ⇒ Object
Return the timezone id of the receiver, or nil if it is a floating time.
-
#tzid=(timezone_id) ⇒ Object
:nodoc:.
-
#utc ⇒ Object
Returns a instance that represents the time in UTC.
-
#utc? ⇒ Boolean
Predicate indicating whether or not the instance represents a ZULU time.
-
#with_floating_timezone ⇒ Object
Return the receiver if it has a floating time zone already, otherwise return a DATETIME property with the same time as the receiver but with a floating time zone.
Instance Method Details
#find_timezone ⇒ Object
:nodoc:
19 20 21 22 23 24 25 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 19 def find_timezone #:nodoc: if @tzid == :floating FloatingTimezone else timezone_finder.find_timezone(@tzid) end end |
#has_local_timezone? ⇒ Boolean
Determine if the receiver has a local time zone, i.e. it is not a floating time or a UTC time
32 33 34 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 32 def has_local_timezone? tzid && tzid.upcase != "UTC" end |
#in_time_zone(new_zone) ⇒ Object
Returns the simultaneous time in the specified zone.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 69 def in_time_zone(new_zone) new_zone = timezone_finder.find_timezone(new_zone) return self if tzid == new_zone.identifier if has_local_timezone? new_zone.utc_to_local(utc) elsif utc? new_zone.utc_to_local(self) else # Floating time DateTime.new(timezone_finder, :value => @date_time_value, :tzid => new_zone.identifier) end end |
#rational_tz_offset ⇒ Object
:nodoc:
55 56 57 58 59 60 61 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 55 def rational_tz_offset #:nodoc: if has_local_timezone? timezone.rational_utc_offset(@date_time_value) else Rational(0,24) end end |
#timezone ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 27 def timezone #:nodoc: @timezone ||= find_timezone end |
#tzid ⇒ Object
Return the timezone id of the receiver, or nil if it is a floating time
9 10 11 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 9 def tzid @tzid == :floating ? nil : @tzid end |
#tzid=(timezone_id) ⇒ Object
:nodoc:
13 14 15 16 17 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 13 def tzid=(timezone_id) #:nodoc: timezone_id = default_tzid if timezone_id == :default @tzid = timezone_id @timezone = nil end |
#utc ⇒ Object
Returns a instance that represents the time in UTC.
47 48 49 50 51 52 53 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 47 def utc if has_local_timezone? timezone.local_to_utc(self) else # Already local or a floating time self end end |
#utc? ⇒ Boolean
Predicate indicating whether or not the instance represents a ZULU time
64 65 66 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 64 def utc? tzid == "UTC" end |
#with_floating_timezone ⇒ Object
Return the receiver if it has a floating time zone already, otherwise return a DATETIME property with the same time as the receiver but with a floating time zone
38 39 40 41 42 43 44 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 38 def with_floating_timezone if @tzid == nil self else @date_time_value.with_floating_timezone.to_ri_cal_date_time_value end end |