# Barry::Sync::TzWrapper Class Reference

`#include <tzwrapper.h>`

Collaboration diagram for Barry::Sync::TzWrapper:

[legend]

List of all members.

## Detailed Description

Wrapper class for the TZ environment variable.

This class allows setting TZ to any number of variables, and will restore the original setting on destruction.

By default, TzWrapper does not change the environment at all, but only saves it. Alternately, you can use the timezone constructor to save and set a new timezone on the fly.

Each Set() and Unset() function returns a reference to TzWrapper, so that you can chain function calls like this:

time_t utc = TzWrapper("Canada/Pacific").mktime(&pacific_tm);

In addition, there are two static utility functions used to convert ISO timestamps to struct tm* and time_t values.

Note: This class is not thread-safe, since it modifies the TZ environment variable without locking. If other threads use time functions, this may interfere with their behaviour.

Definition at line 92 of file tzwrapper.h.

## Public Member Functions

| TzWrapper ()
| Does not change TZ, only saves current setting.
| TzWrapper (const char *timezone)
| Saves current setting and sets TZ to new timezone value.
TzWrapper & | Set (const char *timezone)
| Set TZ to a new value.
TzWrapper & | Unset ()
| Deletes TZ from the environment, which has the same effect as calling SetSysLocal().
TzWrapper & | SetUTC ()
| Set timezone to UTC.
TzWrapper & | SetOffset (int zoneminutes)
| Set timezone via offset in minutes Negative minutes goes west, positive goes east i.e.
TzWrapper & | SetSysLocal ()
| Use system localtime.
TzWrapper & | SetDefault ()
| Use the default TZ value that the user set before running this program.
TzWrapper & | SetOrig ()
| Same as SetDefault().

## Static Public Member Functions

static time_t | iso_mktime (const char *timestamp)
| Converts an ISO timestamp (YYYYMMDDTHHMMWW[Z]) into a unix time_t.

## Constructor & Destructor Documentation

Barry::Sync::TzWrapper::TzWrapper | ( |  | ) | `[inline]`

Does not change TZ, only saves current setting.

Definition at line 121 of file tzwrapper.h.

Barry::Sync::TzWrapper::TzWrapper | ( | const char * | timezone | ) | `[inline, explicit]`

Saves current setting and sets TZ to new timezone value.

If timezone is null, it is the same as calling Unset().

Definition at line 129 of file tzwrapper.h.

## Member Function Documentation

TzWrapper& Barry::Sync::TzWrapper::Set | ( | const char * | timezone | ) | `[inline]`

Set TZ to a new value.

If timezone is null, it is the same as calling Unset().

If timezone is an empty or invalid timezone string, it is the same as calling SetUTC().

Definition at line 146 of file tzwrapper.h.

Referenced by SetOffset().

Here is the caller graph for this function:

TzWrapper& Barry::Sync::TzWrapper::Unset | ( |  | ) | `[inline]`

Deletes TZ from the environment, which has the same effect as calling SetSysLocal().

This is not a permanent condition, since TZ will be restored to original state upon destruction.

Definition at line 161 of file tzwrapper.h.

TzWrapper& Barry::Sync::TzWrapper::SetUTC | ( |  | ) | `[inline]`

Set timezone to UTC.

Definition at line 170 of file tzwrapper.h.

Referenced by iso_mktime().

Here is the caller graph for this function:

TzWrapper & Barry::Sync::TzWrapper::SetOffset | ( | int | zoneminutes | ) |

Set timezone via offset in minutes Negative minutes goes west, positive goes east i.e.

-05:00 is EST

Definition at line 157 of file tzwrapper.cc.

References Set().

Referenced by iso_mktime().

Here is the call graph for this function:

Here is the caller graph for this function:

TzWrapper& Barry::Sync::TzWrapper::SetSysLocal | ( |  | ) | `[inline]`

Use system localtime.

This overrides any TZ value that the user may have set before running your program.

Definition at line 182 of file tzwrapper.h.

TzWrapper& Barry::Sync::TzWrapper::SetDefault | ( |  | ) | `[inline]`

Use the default TZ value that the user set before running this program.

In most cases, this will be the user's preferred local timezone.

Definition at line 190 of file tzwrapper.h.

TzWrapper& Barry::Sync::TzWrapper::SetOrig | ( |  | ) | `[inline]`

Same as SetDefault().

Definition at line 196 of file tzwrapper.h.

time_t Barry::Sync::TzWrapper::iso_mktime | ( | const char * | timestamp | ) | `[static]`

Converts an ISO timestamp (YYYYMMDDTHHMMWW[Z]) into a unix time_t.

If the 'Z' UTC flag is not specified, then the timestamp will be assumed to be in the current default timezone. Otherwise, SetUTC() will be used for the conversion.

This function uses an internal TzWrapper to adjust TZ if necessary, which is why it is a static function of TzWrapper, instead of a standalone function.

Definition at line 183 of file tzwrapper.cc.

References mktime(), SetOffset(), and SetUTC().

Referenced by Barry::Sync::vTimeConverter::vtime2unix().

Here is the call graph for this function:

Here is the caller graph for this function:

The documentation for this class was generated from the following files:

- tzwrapper.h
- tzwrapper.cc