Class: NSTimeZone

Inherits:
NSObject show all

Overview

NSTimeZone is an abstract class that defines the behavior of time zone objects. Time zone objects represent geopolitical regions. Consequently, these objects have names for these regions. Time zone objects also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time).

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Hash) abbreviationDictionary

Returns a dictionary holding the mappings of time zone abbreviations to time zone names. Note that more than one time zone may have the same abbreviation—for example, US/Pacific and Canada/Pacific both use the abbreviation “PST.” In these cases, abbreviationDictionary chooses a single name to map the abbreviation to.

Returns:

  • (Hash)

    A dictionary holding the mappings of time zone abbreviations to time zone names.

+ (NSTimeZone) defaultTimeZone

Returns the default time zone for the current application. The default time zone is the one that the application is running with, which you can change (so you can make the application run as if it were in a different time zone).If you get the default time zone and hold onto the returned object, it does not change if a subsequent invocation of setDefaultTimeZone: changes the default time zone—you still have the specific time zone you originally got. Contrast this behavior with the object returned by localTimeZone.

Returns:

  • (NSTimeZone)

    The default time zone for the current application. If no default time zone has been set, this method invokes systemTimeZone and returns the system time zone.

+ (Array) knownTimeZoneNames

Returns an array of strings listing the IDs of all the time zones known to the system.

Returns:

  • (Array)

    An array of strings listing the IDs of all the time zones known to the system.

+ (NSTimeZone) localTimeZone

Returns an object that forwards all messages to the default time zone for the current application. The local time zone represents the current state of the default time zone at all times. If you get the default time zone (using defaultTimeZone) and hold onto the returned object, it does not change if a subsequent invocation of setDefaultTimeZone: changes the default time zone—you still have the specific time zone you originally got. The local time zone adds a level of indirection, it acts as if it were the current default time zone whenever you invoke a method on it.

Returns:

  • (NSTimeZone)

    An object that forwards all messages to the default time zone for the current application.

+ (Object) resetSystemTimeZone

Resets the system time zone object cached by the application, if any. If the application has cached the system time zone, this method clears that cached object. If you subsequently invoke systemTimeZone, NSTimeZone will attempt to redetermine the system time zone and a new object will be created and cached (see systemTimeZone).

Returns:

+ (Object) setAbbreviationDictionary(dict)

Sets the abbreviation dictionary to the specified dictionary.

Parameters:

  • dict (Hash)

    A dictionary containing key-value pairs for looking up time zone names given their abbreviations. The keys should be NSString objects containing the abbreviations; the values should be NSString objects containing their corresponding geopolitical region names.

Returns:

+ (Object) setDefaultTimeZone(aTimeZone)

Sets the default time zone for the current application to a given time zone. There can be only one default time zone, so by setting a new default time zone, you lose the previous one.

Parameters:

  • aTimeZone (NSTimeZone)

    The new default time zone for the current application.

Returns:

+ (NSTimeZone) systemTimeZone

Returns the time zone currently used by the system.

Returns:

  • (NSTimeZone)

    The time zone currently used by the system. If the current time zone cannot be determined, returns the GMT time zone.

+ (String) timeZoneDataVersion

Returns the time zone data version.

Returns:

  • (String)

    A string containing the time zone data version.

+ (Object) timeZoneForSecondsFromGMT(seconds)

Returns a time zone object offset from Greenwich Mean Time by a given number of seconds. The name of the new time zone is GMT +/– the offset, in hours and minutes. Time zones created with this method never have daylight savings, and the offset is constant no matter the date.

Parameters:

  • seconds (Integer)

    The number of seconds by which the new time zone is offset from GMT.

Returns:

  • (Object)

    A time zone object offset from Greenwich Mean Time by seconds.

+ (Object) timeZoneWithAbbreviation(abbreviation)

Returns the time zone object identified by a given abbreviation. In general, you are discouraged from using abbreviations except for unique instances such as “UTC” or “GMT”. Time Zone abbreviations are not standardized and so a given abbreviation may have multiple meanings—for example, “EST” refers to Eastern Time in both the United States and Australia

Parameters:

  • abbreviation (String)

    An abbreviation for a time zone.

Returns:

  • (Object)

    The time zone object identified by abbreviation determined by resolving the abbreviation to a name using the abbreviation dictionary and then returning the time zone for that name. Returns nil if there is no match for abbreviation.

+ (Object) timeZoneWithName(tzName)

Returns the time zone object identified by a given ID.

Parameters:

  • tzName (String)

    The ID for the time zone.

Returns:

  • (Object)

    The time zone in the information directory with a name matching tzName. Returns nil if there is no match for the name.

+ (Object) timeZoneWithName(tzName, data:data)

Returns the time zone with a given ID whose data has been initialized using given data, You should not call this method directly—use timeZoneWithName: to get the time zone object for a given name.

Parameters:

  • tzName (String)

    The ID for the time zone.

  • data (NSData)

    The data from the time-zone files located at /usr/share/zoneinfo.

Returns:

  • (Object)

    The time zone with the ID tzName whose data has been initialized using the contents of data.

Instance Method Details

- (String) abbreviation

Returns the abbreviation for the receiver. Invokes abbreviationForDate: with the current date as the argument.

Returns:

  • (String)

    The abbreviation for the receiver, such as “EDT” (Eastern Daylight Time).

- (String) abbreviationForDate(aDate)

Returns the abbreviation for the receiver at a given date. Note that the abbreviation may be different at different dates. For example, during daylight savings time the US/Eastern time zone has an abbreviation of “EDT.” At other times, its abbreviation is “EST.”

Parameters:

  • aDate (NSDate)

    The date for which to get the abbreviation for the receiver.

Returns:

  • (String)

    The abbreviation for the receiver at aDate.

- (NSData) data

Returns the data that stores the information used by the receiver. This data should be treated as an opaque object.

Returns:

  • (NSData)

    The data that stores the information used by the receiver.

- (NSTimeInterval) daylightSavingTimeOffset

Returns the current daylight saving time offset of the receiver.

Returns:

  • (NSTimeInterval)

    The daylight current saving time offset of the receiver.

- (NSTimeInterval) daylightSavingTimeOffsetForDate(aDate)

Returns the daylight saving time offset for a given date.

Parameters:

Returns:

  • (NSTimeInterval)

    The daylight saving time offset for aDate.

- (String) description

Returns the description of the receiver.

Returns:

  • (String)

    The description of the receiver, including the name, abbreviation, offset from GMT, and whether or not daylight savings time is currently in effect.

- (Object) initWithName(tzName)

Returns a time zone initialized with a given ID. If tzName is a known ID, this method calls initWithName:data: with the appropriate data object.In OS X v10.4 and earlier providing nil for the parameter would have caused a crash. In OS X v10.5 and later, this now raises an invalid argument exception.

Parameters:

  • tzName (String)

    The ID for the time zone. Must not be nil.

Returns:

  • (Object)

    A time zone object initialized with the ID tzName.

- (Object) initWithName(tzName, data:data)

Initializes a time zone with a given ID and time zone data. You should not call this method directly—use initWithName: to get a time zone object.In OS X v10.4 and earlier providing nil for the tzName parameter would have caused a crash. In OS X v10.5 and later, this now raises an invalid argument exception.

Parameters:

  • tzName (String)

    The ID for the time zone. Must not be nil.

  • data (NSData)

    The data from the time-zone files located at /usr/share/zoneinfo.

Returns:

- (Boolean) isDaylightSavingTime

Returns a Boolean value that indicates whether the receiver is currently using daylight saving time. This method invokes isDaylightSavingTimeForDate: with the current date as the argument.

Returns:

  • (Boolean)

    YES if the receiver is currently using daylight savings time, otherwise NO.

- (Boolean) isDaylightSavingTimeForDate(aDate)

Returns a Boolean value that indicates whether the receiver uses daylight savings time at a given date.

Parameters:

  • aDate (NSDate)

    The date against which to test the receiver.

Returns:

  • (Boolean)

    YES if the receiver uses daylight savings time at aDate, otherwise NO.

- (Boolean) isEqualToTimeZone(aTimeZone)

Returns a Boolean value that indicates whether the receiver has the same name and data as another given time zone.

Parameters:

  • aTimeZone (NSTimeZone)

    The time zone to compare with the receiver.

Returns:

  • (Boolean)

    YES if aTimeZone and the receiver have the same name and data, otherwise NO.

- (String) localizedName(style, locale:locale)

Returns the name of the receiver localized for a given locale.

Parameters:

  • style (NSTimeZoneNameStyle)

    The format style for the returned string.

  • locale (NSLocale)

    The locale for which to format the name.

Returns:

  • (String)

    The name of the receiver localized for locale using style.

- (String) name

Returns the geopolitical region ID that identifies the receiver.

Returns:

  • (String)

    The geopolitical region ID that identifies the receiver.

- (NSDate) nextDaylightSavingTimeTransition

Returns the date of the next daylight saving time transition for the receiver.

Returns:

  • (NSDate)

    The date of the next (after the current instant) daylight saving time transition for the receiver.

- (NSDate) nextDaylightSavingTimeTransitionAfterDate(aDate)

Returns the next daylight saving time transition after a given date.

Parameters:

Returns:

  • (NSDate)

    The next daylight saving time transition after aDate.

- (Integer) secondsFromGMT

Returns the current difference in seconds between the receiver and Greenwich Mean Time.

Returns:

  • (Integer)

    The current difference in seconds between the receiver and Greenwich Mean Time.

- (Integer) secondsFromGMTForDate(aDate)

Returns the difference in seconds between the receiver and Greenwich Mean Time at a given date. The difference may be different from the current difference if the time zone changes its offset from GMT at different points in the year—for example, the U.S. time zones change with daylight savings time.

Parameters:

  • aDate (NSDate)

    The date against which to test the receiver.

Returns:

  • (Integer)

    The difference in seconds between the receiver and Greenwich Mean Time at aDate.