## GTimeZone

GTimeZone — a structure representing a time zone

## Synopsis

    #include <glib.h>

                        GTimeZone;
    void                g_time_zone_unref                   (GTimeZone *tz);
    GTimeZone *         g_time_zone_ref                     (GTimeZone *tz);

    GTimeZone *         g_time_zone_new                     (const gchar *identifier);
    GTimeZone *         g_time_zone_new_local               (void);
    GTimeZone *         g_time_zone_new_utc                 (void);

    enum                GTimeType;
    gint                g_time_zone_find_interval           (GTimeZone *tz,
                                                             GTimeType type,
                                                             gint64 time_);
    gint                g_time_zone_adjust_time             (GTimeZone *tz,
                                                             GTimeType type,
                                                             gint64 *time_);

    const gchar *       g_time_zone_get_abbreviation        (GTimeZone *tz,
                                                             gint interval);
    gint32              g_time_zone_get_offset              (GTimeZone *tz,
                                                             gint interval);
    gboolean            g_time_zone_is_dst                  (GTimeZone *tz,
                                                             gint interval);

## Description

GTimeZone is a structure that represents a time zone, at no particular point in time. It is refcounted and immutable.

A time zone contains a number of intervals. Each interval has an abbreviation to describe it, an offet 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.

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.

GTimeZone is available since GLib 2.26.

## Details

### GTimeZone

    typedef struct _GTimeZone GTimeZone;

GDateTime is an opaque structure whose members cannot be accessed directly.

Since 2.26

### g_time_zone_unref ()

    void                g_time_zone_unref                   (GTimeZone *tz);

Decreases the reference count on `tz`.

`tz` : | a GTimeZone

Since 2.26

### g_time_zone_ref ()

    GTimeZone *         g_time_zone_ref                     (GTimeZone *tz);

Increases the reference count on `tz`.

`tz` : | a GTimeZone
Returns : | a new reference to `tz`.

Since 2.26

### g_time_zone_new ()

    GTimeZone *         g_time_zone_new                     (const gchar *identifier);

Creates a GTimeZone corresponding to `identifier`.

`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`).

Valid RFC3339 time offsets are `"Z"` (for UTC) or `"±hh:mm"`. ISO 8601 additionally specifies `"±hhmm"` and `"±hh"`.

The `TZ` environment variable typically corresponds to the name of a file in the zoneinfo database, but there are many other possibilities. Note that those other possibilities are not currently implemented, but are planned.

`g_time_zone_new_local()` calls this function with the value of the `TZ` environment variable. This function itself is independent of the value of `TZ`, but if `identifier` is `NULL` then `/etc/localtime` will be consulted to discover the correct timezone.

See RFC3339 §5.6 for a precise definition of valid RFC3339 time offsets (the `time-offset` expansion) and ISO 8601 for the full list of valid time offsets. See The GNU C Library manual for an explanation of the possible values of the `TZ` environment variable.

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

`identifier` : | a timezone identifier. [allow-none]
Returns : | the requested timezone

Since 2.26

### g_time_zone_new_local ()

    GTimeZone *         g_time_zone_new_local               (void);

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

### g_time_zone_new_utc ()

    GTimeZone *         g_time_zone_new_utc                 (void);

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

### enum GTimeType

    typedef enum {
      G_TIME_TYPE_STANDARD,
      G_TIME_TYPE_DAYLIGHT,
      G_TIME_TYPE_UNIVERSAL
    } GTimeType;

Disambiguates a given time in two ways.

First, specifies if the given time is in universal or local time.

Second, if the time is in local time, specifies if it is local standard time or local daylight time. This is important for the case where the same local time occurs twice (during daylight savings time transitions, for example).

`G_TIME_TYPE_STANDARD` | the time is in local standard time
`G_TIME_TYPE_DAYLIGHT` | the time is in local daylight time
`G_TIME_TYPE_UNIVERSAL` | the time is in UTC

### g_time_zone_find_interval ()

    gint                g_time_zone_find_interval           (GTimeZone *tz,
                                                             GTimeType type,
                                                             gint64 time_);

Finds an the interval within `tz` that corresponds to the given `time_`. The meaning of `time_` depends on `type`.

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

Otherwise `time_` is treated is local time. The distinction between `G_TIME_TYPE_STANDARD` and `G_TIME_TYPE_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.

`tz` : | a GTimeZone
`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

### g_time_zone_adjust_time ()

    gint                g_time_zone_adjust_time             (GTimeZone *tz,
                                                             GTimeType type,
                                                             gint64 *time_);

Finds an interval within `tz` 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.

`tz` : | a GTimeZone
`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

### g_time_zone_get_abbreviation ()

    const gchar *       g_time_zone_get_abbreviation        (GTimeZone *tz,
                                                             gint 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.

`tz` : | a GTimeZone
`interval` : | an interval within the timezone
Returns : | the time zone abbreviation, which belongs to `tz`

Since 2.26

### g_time_zone_get_offset ()

    gint32              g_time_zone_get_offset              (GTimeZone *tz,
                                                             gint 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 `tz` (ie: negative numbers for time zones west of GMT, positive numbers for east).

`tz` : | a GTimeZone
`interval` : | an interval within the timezone
Returns : | the number of seconds that should be added to UTC to get the local time in `tz`

Since 2.26

### g_time_zone_is_dst ()

    gboolean            g_time_zone_is_dst                  (GTimeZone *tz,
                                                             gint interval);

Determines if daylight savings time is in effect during a particular `interval` of time in the time zone `tz`.

`tz` : | a GTimeZone
`interval` : | an interval within the timezone
Returns : | `TRUE` if daylight savings time is in effect

Since 2.26

## See Also

GDateTime