Class TimeZone
In: lib/active_support/values/time_zone.rb
Parent: Object

A value object representing a time zone. A time zone is simply a named offset (in seconds) from GMT. Note that two time zone objects are only equivalent if they have both the same offset, and the same name.

A TimeZone instance may be used to convert a Time value to the corresponding time zone.

The class also includes all, which returns a list of all TimeZone objects.

Methods

<=>   []   adjust   all   create   formatted_offset   new   new   now   to_s   today   unadjust   us_zones  

Included Modules

Comparable

Constants

US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/   A regular expression that matches the names of all time zones in the USA.

Attributes

name  [R] 
utc_offset  [R] 

Public Class methods

Locate a specific time zone object. If the argument is a string, it is interpreted to mean the name of the timezone to locate. If it is a numeric value it is either the hour offset, or the second offset, of the timezone to find. (The first one with that offset will be returned.) Returns nil if no such time zone is known to the system.

Return an array of all TimeZone objects. There are multiple TimeZone objects per time zone, in many cases, to make it easier for users to find their own time zone.

Create a new TimeZone instance with the given name and offset.

Create a new TimeZone object with the given name and offset. The offset is the number of seconds that this time zone is offset from UTC (GMT). Seconds were chosen as the offset unit because that is the unit that Ruby uses to represent time zone offsets (see Time#utc_offset).

Return a TimeZone instance with the given name, or nil if no such TimeZone instance exists. (This exists to support the use of this class with the composed_of macro.)

A convenience method for returning a collection of TimeZone objects for time zones in the USA.

Public Instance methods

Compare this time zone to the parameter. The two are comapred first on their offsets, and then by name.

Adjust the given time to the time zone represented by self.

Returns the offset of this time zone as a formatted string, of the format "+HH:MM". If the offset is zero, this returns the empty string. If colon is false, a colon will not be inserted into the result.

Compute and return the current time, in the time zone represented by self.

Returns a textual representation of this time zone.

Return the current date in this time zone.

Reinterprets the given time value as a time in the current time zone, and then adjusts it to return the corresponding time in the local time zone.

[Validate]