PATH Documentation > WebObjects

Table of Contents

NSTimeZone


Inherits from:
java.util.TimeZone : Object
Implements:
Cloneable
Serializable
NSCoding
Package:
com.webobjects.foundation


Class Description


NSTimeZone 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").

NSTimeZone provides several constructors to get time zone objects. The class also permits you to set the default time zone within your application ( setDefaultTimeZone). You can access this default time zone at any time with the defaultTimeZone static method, and with the localTimeZone static method, you can get a relative time zone object that decodes itself to become the default time zone for any locale in which it finds itself.

Because NSTimeZone is a subclass of java.util.TimeZone, you can also use the java.util.TimeZone API with NSTimeZones.

WARNING NSTimeZone is only intended to be used with NSTimestamp and NSTimestampFormatter. It produces incorrect results when used with Java's date-related classes.

Some NSTimestamp methods return date objects that are automatically bound to time zone objects. These date objects use the functionality of NSTimeZone to adjust dates for the proper locale. Unless you specify otherwise, objects returned from NSTimestamp are bound to the default time zone for the current locale.




Interfaces Implemented


Cloneable
clone
java.io.Serializable
NSCoding
decodeObject
classForCoder
encodeWithCoder


Method Types


Constructors
NSTimeZone
Getting the default time zone
localTimeZone
defaultTimeZone
setDefaultTimeZone
resetSystemTimeZone
Getting time zone information
abbreviationDictionary
knownTimeZoneNames
Getting information about a specific time zone
abbreviation
abbreviationForTimestamp
name
secondsFromGMT
secondsFromGMTForTimestamp
isDaylightSavingTime
isDaylightSavingTimeForTimestamp
data
Comparing time zones
equals
isEqualToTimeZone
Instance methods inherited from java.util.TimeZone
getAvailableIDs
getDefault
getDisplayName
getID
getOffset
getRawOffset
hasSameRules
inDaylightTime
setDefault
setID
setRawOffset
useDaylightTime


Constructors



NSTimeZone

public NSTimeZone()

This constructor is used internally to implement the java.io.Serializable and java.io.Externalizable interfaces and should be considered private. Use the static factory methods to create time zones.

protected NSTimeZone( String aTimeZoneName, NSData data)

This constructor is used internally by NSTimeZone and should be considered private. Use the static factory methods to create time zones.




Static Methods



abbreviationDictionary

public static NSDictionary abbreviationDictionary()

Returns a dictionary holding the mappings of time zone abbreviations to time zone names.

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.



decodeObject

public static Object decodeObject(NSCoder coder)

Creates and returns an NSTimeZone from the data in coder.

See Also: NSCoding Interface Description



defaultTimeZone

public static synchronized NSTimeZone defaultTimeZone()

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

See Also: localTimeZone, setDefaultTimeZone, systemTimeZone



getAvailableIDs

public static String[] getAvailableIDs()

See the method description for getAvailableIDs in the java.util.TimeZone class specification.

getDefault

public static java.util.TimeZone getDefault()

See the method description for getDefault in the java.util.TimeZone class specification.

knownTimeZoneNames

public static NSArray knownTimeZoneNames()

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

localTimeZone

public static NSTimeZone localTimeZone()

Returns an object that forwards all messages to the default time zone for your application. This behavior is particularly useful for NSTimestamp objects that are archived or sent as Distributed Objects and may be interpreted in different locales.

See Also: defaultTimeZone, setDefaultTimeZone



resetSystemTimeZone

public static synchronized void resetSystemTimeZone()

Clears the previously determined system time zone, if any. Subsequent calls to systemTimeZone will attempt to redetermine the system time zone.

setDefault

public static synchronized void setDefault(java.util.TimeZone zone)

See the method description for setDefault in the java.util.TimeZone class specification.

setDefaultTimeZone

public static synchronized void setDefaultTimeZone(NSTimeZone aTimeZone)

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

See Also: defaultTimeZone, localTimeZone



systemTimeZone

public static synchronized NSTimeZone systemTimeZone()

Returns the time zone currently used by the system. If it can't figure out the current time zone, returns the GMT time zone.

timeZoneForSecondsFromGMT

public static synchronized NSTimeZone timeZoneForSecondsFromGMT(int seconds)

Returns a time zone object with seconds offset from Greenwich Mean Time. The name of the new time zone is GMT +/- the offset, in hours and minutes. Time zones created with this never have daylight savings and the offset is constant no matter the date; the name and abbreviation do NOT follow the POSIX convention of minutes-west.

See Also: timeZoneWithName



timeZoneWithName

public static synchronized NSTimeZone timeZoneWithName( String aTimeZoneName, boolean trybbreviation)

Returns the time zone object identified by the name aTimeZoneName. If tryAbbreviation is false, this method searches the time zone information directory for matching names. If tryAbbreviation is true, this method attempts to resolve the abbreviation to a name using the abbreviation dictionary. Returns null if there is no match on the name.

See Also: timeZoneForSecondsFromGMT, knownTimeZoneNames



timeZoneWithNameAndData

public static synchronized NSTimeZone timeZoneWithNameAndData( String aTimeZoneName, NSData data)

Returns the time zone with the name aTimeZoneName whose data has been initialized using the contents of data. You should not call this method directly-use timeZoneWithName instead.


Instance Methods



abbreviation

public String abbreviation()

Returns the abbreviation for the time zone, such as "EDT" (Eastern Daylight Time). Invokes abbreviationForTimestamp with the current date as the argument.

abbreviationForTimestamp

public String abbreviationForTimestamp(NSTimestamp aTimestamp)

Returns the abbreviation for the time zone object at the date specified by aTimestamp. 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."

classForCoder

public Class classForCoder()

Conformance to NSCoding.

See Also: classForCoder (NSCoding)



clone

public Object clone()

Simply returns the receiver. Since NSArrays are immutable, there's no need to make an actual clone.

data

public NSData data()

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

encodeWithCoder

public void encodeWithCoder(NSCoder coder)

Conformance to NSCoding. See the method description for encodeWithCoder in the NSCoding interface specification.

equals

public boolean equals(Object anObject)

Returns true if anObject is an NSTimeZone and its contents are equal to the receiver's or false otherwise. If you know that anObject is an NSTimestamp, use the more efficient method isEqualToTimeZone instead.

getDisplayName

public String getDisplayName( boolean daylight, int style, java.util.Locale locale)

Returns the name of the equivalent java.util.SimpleTimeZone if one exists. Otherwise returns the receiver's geopolitical region name.

getID

public String getID()

Returns the receiver's geopolitical region name.

getOffset

public int getOffset( int era, int year, int month, int day, int dayOfWeek, int milliseconds)

See the method description for getOffset in the java.util.TimeZone class specification.

getRawOffset

public int getRawOffset()

See the method description for getRawOffset in the java.util.TimeZone class specification. For NSTimeZones, this method always returns 0.

hashCode

public synchronized int hashCode()

See the method description for hashCode in the Object class specification.

hasSameRules

public boolean hasSameRules(java.util.TimeZone other)

Returns true if other is the same as the receiver (as determined by equals.).

inDaylightTime

public boolean inDaylightTime(java.util.Date date)

See the method description for inDaylightTime in the java.util.TimeZone class specification.

isDaylightSavingTime

public boolean isDaylightSavingTime()

Returns true if the time zone is currently using Daylight Savings Time. This method invokes isDaylightSavingTimeForTimestamp with the current date as the argument.

isDaylightSavingTimeForTimestamp

public boolean isDaylightSavingTimeForTimestamp(NSTimestamp aTimestamp)

Returns true if the time zone uses Daylight Savings Time at the date specified by aTimestamp.

isEqualToTimeZone

public boolean isEqualToTimeZone(NSTimeZone aTimeZone)

Returns true if aTimeZone and the receiving time zone have the same name and data.

name

public String name()

Returns the geopolitical region name that identifies the time zone.

readExternal

public void readExternal(java.io.ObjectInput input) throws java.io.IOException,ClassNotFoundException

Description forthcoming.

readResolve

public Object readResolve() throws java.io.ObjectStreamException

Conformance to java.io.Serializable.

secondsFromGMT

public int secondsFromGMT()

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

secondsFromGMTForTimestamp

public int secondsFromGMTForTimestamp(NSTimestamp aTimestamp)

Returns the difference in seconds between the time zone and Greenwich Mean Time at the date specified by aTimestamp. This 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.

setID

public void setID(String ID)

Throws an IllegalStateException because NSTimeZones are immutable.

setRawOffset

public void setRawOffset(int offsetMillis)

Throws an IllegalStateException because NSTimeZones are immutable.

toString

public String toString()

Returns a string representation of the receiver that indicates the receiver's name, the receiver's current offset from GMT, and whether the receiver is currently using Daylight Savings Time.

useDaylightTime

public boolean useDaylightTime()

See the method description for useDaylightTime in the java.util.TimeZone class specification.

writeExternal

public void writeExternal( java.io.ObjectOutput output) throws java.io.IOException

Description forthcoming.


Notifications


SystemTimeZoneDidChangeNotification

public static final String SystemTimeZoneDidChangeNotification;


© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents