Class TimeZone

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class TimeZone extends ProxyInstance

A GTimeZone represents a time zone, at no particular point in time.

The GTimeZone struct is refcounted and immutable.

Each time zone has an identifier (for example, ‘Europe/London’) which is platform dependent. See TimeZone(String) for information on the identifier formats. The identifier of a time zone can be retrieved using getIdentifier().

A time zone contains a number of intervals. Each interval has an abbreviation to describe it (for example, ‘PDT’), an offset to UTC and a flag indicating if the daylight savings time is in effect during that interval. A time zone always has at least one interval — interval 0. Note that interval abbreviations are not the same as time zone identifiers (apart from ‘UTC’), and cannot be passed to TimeZone(String).

Every UTC time is contained within exactly one interval, but a given local time may be contained within zero, one or two intervals (due to incontinuities associated with daylight savings time).

An interval may refer to a specific period of time (eg: the duration of daylight savings time during 2010) or it may refer to many periods of time that share the same properties (eg: all periods of daylight savings time). It is also possible (usually for political reasons) that some properties (like the abbreviation) change between intervals without other properties changing.

Since:
2.26
  • Constructor Summary

    Constructors
    Constructor
    Description
    TimeZone(@Nullable String identifier)
    Deprecated.
    Use g_time_zone_new_identifier() instead, as it provides error reporting.
    Create a TimeZone proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    adjustTime(TimeType type, Out<Long> time)
    Finds an interval within this TimeZone that corresponds to the given time, possibly adjusting time if required to fit into an interval.
    int
    findInterval(TimeType type, long time)
    Finds an interval within this TimeZone that corresponds to the given time. The meaning of time depends on type.
    getAbbreviation(int interval)
    Determines the time zone abbreviation to be used during a particular interval of time in the time zone tz.
    Get the identifier of this GTimeZone, as passed to g_time_zone_new().
    The memory layout of the native struct.
    int
    getOffset(int interval)
    Determines the offset to UTC in effect during a particular interval of time in the time zone tz.
    static @Nullable Type
    Get the GType of the TimeZone class.
    static @Nullable TimeZone
    identifier(@Nullable String identifier)
    Creates a GTimeZone corresponding to identifier. If identifier cannot be parsed or loaded, null is returned.
    boolean
    isDst(int interval)
    Determines if daylight savings time is in effect during a particular interval of time in the time zone tz.
    static TimeZone
    Creates a GTimeZone corresponding to local time.
    static TimeZone
    offset(int seconds)
    Creates a GTimeZone corresponding to the given constant offset from UTC, in seconds.
    ref()
    Increases the reference count on tz.
    void
    Decreases the reference count on tz.
    static TimeZone
    utc()
    Creates a GTimeZone corresponding to UTC.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TimeZone

      public TimeZone(MemorySegment address)
      Create a TimeZone proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • TimeZone

      @Deprecated public TimeZone(@Nullable String identifier)
      Deprecated.
      Use g_time_zone_new_identifier() instead, as it provides error reporting. Change your code to handle a potentially null return value.

      A version of g_time_zone_new_identifier() which returns the UTC time zone if identifier could not be parsed or loaded.

      If you need to check whether identifier was loaded successfully, use g_time_zone_new_identifier().

      Parameters:
      identifier - a timezone identifier
      Since:
      2.26
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the TimeZone class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • identifier

      public static @Nullable TimeZone identifier(@Nullable String identifier)

      Creates a GTimeZone corresponding to identifier. If identifier cannot be parsed or loaded, null is returned.

      identifier can either be an RFC3339/ISO 8601 time offset or something that would pass as a valid value for the TZ environment variable (including null).

      In Windows, identifier can also be the unlocalized name of a time zone for standard time, for example "Pacific Standard Time".

      Valid RFC3339 time offsets are "Z" (for UTC) or "±hh:mm". ISO 8601 additionally specifies "±hhmm" and "±hh". Offsets are time values to be added to Coordinated Universal Time (UTC) to get the local time.

      In UNIX, the TZ environment variable typically corresponds to the name of a file in the zoneinfo database, an absolute path to a file somewhere else, or a string in "std offset identifier is %NULL then /etc/localtime` will be consulted to discover the correct time zone on UNIX and the registry will be consulted or GetTimeZoneInformation() will be used to get the local time zone on Windows.

      If intervals are not available, only time zone rules from TZ environment variable or other means, then they will be computed from year 1900 to 2037. If the maximum year for the rules is available and it is greater than 2037, then it will followed instead.

      See [RFC3339 §5.6(http://tools.ietf.org/html/rfc3339section-5.6) for a precise definition of valid RFC3339 time offsets (the time-offsetexpansion) and ISO 8601 for the full list of valid time offsets. See [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html) for an explanation of the possible values of theTZ` environment variable. See Microsoft Time Zone Index Values for the list of time zones on Windows.

      You should release the return value by calling g_time_zone_unref() when you are done with it.

      Parameters:
      identifier - a timezone identifier
      Returns:
      the requested timezone, or null on failure
      Since:
      2.68
    • local

      public static TimeZone local()

      Creates a GTimeZone corresponding to local time. The local time zone may change between invocations to this function; for example, if the system administrator changes it.

      This is equivalent to calling g_time_zone_new() with the value of the TZ environment variable (including the possibility of null).

      You should release the return value by calling g_time_zone_unref() when you are done with it.

      Returns:
      the local timezone
      Since:
      2.26
    • offset

      public static TimeZone offset(int seconds)

      Creates a GTimeZone corresponding to the given constant offset from UTC, in seconds.

      This is equivalent to calling g_time_zone_new() with a string in the form [+|-]hh[:mm[:ss]].

      It is possible for this function to fail if seconds is too big (greater than 24 hours), in which case this function will return the UTC timezone for backwards compatibility. To detect failures like this, use g_time_zone_new_identifier() directly.

      Parameters:
      seconds - offset to UTC, in seconds
      Returns:
      a timezone at the given offset from UTC, or UTC on failure
      Since:
      2.58
    • utc

      public static TimeZone utc()

      Creates a GTimeZone corresponding to UTC.

      This is equivalent to calling g_time_zone_new() with a value like "Z", "UTC", "+00", etc.

      You should release the return value by calling g_time_zone_unref() when you are done with it.

      Returns:
      the universal timezone
      Since:
      2.26
    • adjustTime

      public int adjustTime(TimeType type, Out<Long> time)

      Finds an interval within this TimeZone that corresponds to the given time, possibly adjusting time if required to fit into an interval. The meaning of time depends on type.

      This function is similar to g_time_zone_find_interval(), with the difference that it always succeeds (by making the adjustments described below).

      In any of the cases where g_time_zone_find_interval() succeeds then this function returns the same value, without modifying time.

      This function may, however, modify time in order to deal with non-existent times. If the non-existent local time of 02:30 were requested on March 14th 2010 in Toronto then this function would adjust time to be 03:00 and return the interval containing the adjusted time.

      Parameters:
      type - the GTimeType of time
      time - a pointer to a number of seconds since January 1, 1970
      Returns:
      the interval containing time, never -1
      Since:
      2.26
    • findInterval

      public int findInterval(TimeType type, long time)

      Finds an interval within this TimeZone that corresponds to the given time. The meaning of time depends on type.

      If type is TimeType.UNIVERSAL then this function will always succeed (since universal time is monotonic and continuous).

      Otherwise time is treated as local time. The distinction between TimeType.STANDARD and TimeType.DAYLIGHT is ignored except in the case that the given time is ambiguous. In Toronto, for example, 01:30 on November 7th 2010 occurred twice (once inside of daylight savings time and the next, an hour later, outside of daylight savings time). In this case, the different value of type would result in a different interval being returned.

      It is still possible for this function to fail. In Toronto, for example, 02:00 on March 14th 2010 does not exist (due to the leap forward to begin daylight savings time). -1 is returned in that case.

      Parameters:
      type - the GTimeType of time
      time - a number of seconds since January 1, 1970
      Returns:
      the interval containing time, or -1 in case of failure
      Since:
      2.26
    • getAbbreviation

      public String getAbbreviation(int interval)

      Determines the time zone abbreviation to be used during a particular interval of time in the time zone tz.

      For example, in Toronto this is currently "EST" during the winter months and "EDT" during the summer months when daylight savings time is in effect.

      Parameters:
      interval - an interval within the timezone
      Returns:
      the time zone abbreviation, which belongs to this TimeZone
      Since:
      2.26
    • getIdentifier

      public String getIdentifier()

      Get the identifier of this GTimeZone, as passed to g_time_zone_new(). If the identifier passed at construction time was not recognised, UTC will be returned. If it was null, the identifier of the local timezone at construction time will be returned.

      The identifier will be returned in the same format as provided at construction time: if provided as a time offset, that will be returned by this function.

      Returns:
      identifier for this timezone
      Since:
      2.58
    • getOffset

      public int getOffset(int interval)

      Determines the offset to UTC in effect during a particular interval of time in the time zone tz.

      The offset is the number of seconds that you add to UTC time to arrive at local time for this TimeZone (ie: negative numbers for time zones west of GMT, positive numbers for east).

      Parameters:
      interval - an interval within the timezone
      Returns:
      the number of seconds that should be added to UTC to get the local time in this TimeZone
      Since:
      2.26
    • isDst

      public boolean isDst(int interval)
      Determines if daylight savings time is in effect during a particular interval of time in the time zone tz.
      Parameters:
      interval - an interval within the timezone
      Returns:
      true if daylight savings time is in effect
      Since:
      2.26
    • ref

      public TimeZone ref()
      Increases the reference count on tz.
      Returns:
      a new reference to tz.
      Since:
      2.26
    • unref

      public void unref()
      Decreases the reference count on tz.
      Since:
      2.26