Class

TimeWithZone

Extends:

Includes:

A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are limited to UTC and the system’s ENV[‘TZ’] zone

Public Attributes
time_zone
Public Methods
- Need to override #- to intercept situation where a Time or Time With Zone object is passed in Otherwise, just pass on to method missing
<=> Use the time in UTC for comparisons
acts_like_time? so that self acts_like?(:time)
change_time_zone Changes the time zone without converting the time
change_time_zone_to_current Changes the time zone to Time.zone without converting the time
comparable_time Alias for #utc
dst?
formatted_offset
freeze Neuter freeze because freezing can cause problems with lazy loading of attributes
in_current_time_zone Returns the simultaneous time in Time.zone
in_time_zone Returns the simultaneous time in the specified zone
inspect
is_a? Say we’re a Time to thwart type checking
kind_of? Alias for #is_a?
localtime Returns a Time.local() instance of the simultaneous time in your system’s ENV[‘TZ’] zone
method_missing Send the missing method to time instance, and wrap result in a new TimeWithZone with the existing time_zone
new
period Returns the underlying TZInfo::TimezonePeriod for the local time
respond_to? Ensure proxy class responds to all methods that underlying time instance responds to
strftime Replaces %Z and %z directives with #zone and #formatted_offset, respectively, before passing to Time#strftime, so that zone information is correct
time Returns a Time instance that represents the time in time_zone
to_json
to_s :db format outputs time in UTC; all others output time in local. Uses TimeWithZone’s strftime, so %Z and %z work correctly
to_time A TimeProxy acts like a Time, so just return self
utc Returns a Time instance that represents the time in UTC
utc?
utc_offset
xmlschema
zone Time uses #zone to display the time zone abbreviation, so we’re duck-typing it
Private Methods
get_period_for_local
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.