Module: RiCal::PropertyValue::TimezoneSupport
- Included in:
- 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 ethods for DateTime
Instance Method Summary collapse
-
#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.
-
#timezone ⇒ Object
:nodoc:.
-
#tzid ⇒ Object
Return the timezone id of the receiver, or nil if it is a floating time.
-
#tzid=(string) ⇒ 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
#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
23 24 25 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 23 def has_local_timezone? tzid && tzid != "UTC" end |
#in_time_zone(new_zone) ⇒ Object
Returns the simultaneous time in the specified zone.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 52 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 |
#timezone ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 18 def timezone #:nodoc: @timezone ||= timezone_finder.find_timezone(@tzid) 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 end |
#tzid=(string) ⇒ Object
:nodoc:
13 14 15 16 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 13 def tzid=(string) #:nodoc: @tzid = string @timezone = nil end |
#utc ⇒ Object
Returns a instance that represents the time in UTC.
38 39 40 41 42 43 44 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 38 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
47 48 49 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 47 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
29 30 31 32 33 34 35 |
# File 'lib/ri_cal/property_value/date_time/timezone_support.rb', line 29 def with_floating_timezone if @tzid == nil self else @date_time_value.with_floating_timezone.to_ri_cal_date_time_value end end |