glibmm 2.34.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Attributes | Related Functions | List of all members
Glib::TimeZone Class Reference

TimeZone - A structure representing a time zone. More...

`#include <glibmm/timezone.h>`

## Public Member Functions

| TimeZone ()
| TimeZone (GTimeZone* castitem, bool make_a_copy=false)
| TimeZone (const TimeZone& src)
TimeZone& | operator= (const TimeZone& src)
| ~TimeZone ()
GTimeZone* | gobj ()
const GTimeZone* | gobj () const
GTimeZone* | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
int | find_interval (TimeType type, gint64 time) const
| Finds an the interval within tz that corresponds to the given time.
int | adjust_time (TimeType type, gint64& time) const
| Finds an interval within tz that corresponds to the given time, possibly adjusting time if required to fit into an interval.
Glib::ustring | get_abbreviation (int interval) const
| Determines the time zone abbreviation to be used during a particular interval of time in the time zone tz.
gint32 | get_offset (int interval) const
| Determines the offset to UTC in effect during a particular interval of time in the time zone tz.
bool | is_dst (int interval) const
| Determines if daylight savings time is in effect during a particular interval of time in the time zone tz.

## Static Public Member Functions

static TimeZone | create (const Glib::ustring& identifier)
| Creates a TimeZone corresponding to identifier.
static TimeZone | create_local ()
| Creates a TimeZone corresponding to local time.
static TimeZone | create_utc ()
| Creates a TimeZone corresponding to UTC.

## Protected Attributes

GTimeZone* | gobject_

## Related Functions

(Note that these are not member functions.)
Glib::TimeZone | wrap (GTimeZone* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

TimeZone - A structure representing a time zone.

TimeZone 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.

Since glibmm 2.30:

## Constructor & Destructor Documentation

Glib::TimeZone::TimeZone | ( |  | ) |

Glib::TimeZone::TimeZone | ( | GTimeZone * | castitem,
|  | bool | make_a_copy = `false`
| ) |  |

explicit

Glib::TimeZone::TimeZone | ( | const TimeZone& | src | ) |

Glib::TimeZone::~TimeZone | ( |  | ) |

## Member Function Documentation

int Glib::TimeZone::adjust_time | ( | TimeType | type,
|  | gint64 & | time
| ) |  | const

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.

Since glibmm 2.26:

Parameters

  type | The TimeType of time.
  time | A pointer to a number of seconds since January 1, 1970.

Returns
  The interval containing time, never -1.

static TimeZone Glib::TimeZone::create | ( | const Glib::ustring& | identifier | ) |

static

Creates a TimeZone corresponding to identifier.

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

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

The <varname>TZ</varname> 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 <varname>TZ</varname> environment variable. This function itself is independent of the value of <varname>TZ</varname>, but if identifier is `0` then <filename>/etc/localtime</filename> will be consulted to discover the correct timezone.

See RFC3339 §5.6 for a precise definition of valid RFC3339 time offsets (the <varname>time-offset</varname> 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 <varname>TZ</varname> environment variable.

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

Since glibmm 2.26:

Parameters

  identifier | A timezone identifier.

Returns
  The requested timezone.

static TimeZone Glib::TimeZone::create_local | ( |  | ) |

static

Creates a TimeZone 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 <varname>TZ</varname> environment variable (including the possibility of `0`).

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

Since glibmm 2.26:

Returns
  The local timezone.

static TimeZone Glib::TimeZone::create_utc | ( |  | ) |

static

Creates a TimeZone 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.

Since glibmm 2.26:

Returns
  The universal timezone.

int Glib::TimeZone::find_interval | ( | TimeType | type,
|  | gint64 | time
| ) |  | const

Finds an the interval within tz that corresponds to the given time.

The meaning of time depends on type.

If type is 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 TIME_TYPE_STANDARD and 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.

Since glibmm 2.26:

Parameters

  type | The TimeType of time.
  time | A number of seconds since January 1, 1970.

Returns
  The interval containing time, or -1 in case of failure.

Glib::ustring Glib::TimeZone::get_abbreviation | ( | int | interval | ) | const

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.

Since glibmm 2.26:

Parameters

  interval | An interval within the timezone.

Returns
  The time zone abbreviation, which belongs to tz.

gint32 Glib::TimeZone::get_offset | ( | int | interval | ) | const

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

Since glibmm 2.26:

Parameters

  interval | An interval within the timezone.

Returns
  The number of seconds that should be added to UTC to get the local time in tz.

GTimeZone* Glib::TimeZone::gobj | ( |  | ) |

inline

const GTimeZone* Glib::TimeZone::gobj | ( |  | ) | const

inline

GTimeZone* Glib::TimeZone::gobj_copy | ( |  | ) | const

Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.

bool Glib::TimeZone::is_dst | ( | int | interval | ) | const

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

Since glibmm 2.26:

Parameters

  interval | An interval within the timezone.

Returns
  `true` if daylight savings time is in effect.

TimeZone& Glib::TimeZone::operator= | ( | const TimeZone& | src | ) |

## Friends And Related Function Documentation

Glib::TimeZone wrap | ( | GTimeZone * | object,
|  | bool | take_copy = `false`
| ) |  |

related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.

## Member Data Documentation

GTimeZone* Glib::TimeZone::gobject_

protected