TZ-Lib
$VERSION$
|
#include <tzdata.h>
Public Types | |
enum | WeekDay { Sunday =0, Monday =1, Tuesday =2, Wednesday =3, Thursday =4, Friday =5, Saturday =6 } |
Public Member Functions | |
TimeStamp () | |
TimeStamp (qint64 ts, bool isLocal=true) | |
TimeStamp (qint64 ts, QString zone) | |
TimeStamp (qint64 ts, quint16 msec, bool isLocal=true) | |
TimeStamp (qint64 ts, quint16 msec, QString zone) | |
TimeStamp (const QDate &, bool isLocal=true) | |
TimeStamp (const QDate &, QString) | |
TimeStamp (const QTime &, bool isLocal=true) | |
TimeStamp (const QTime &, QString) | |
TimeStamp (const QDateTime &ts) | |
TimeStamp (const QDateTime &ts, bool isLocal) | |
TimeStamp (const QDateTime &ts, QString zone) | |
TimeStamp (const TimeStamp &) | |
void | addDays (int d) |
void | addMSecs (int msec) |
void | addSecs (int sec) |
quint8 | day () const |
quint8 | hour () const |
quint8 | minute () const |
quint8 | month () const |
void | moveToLocal () |
void | moveToUTC () |
bool | moveToZone (QString) |
quint16 | msecs () const |
qint32 | offsetFromUTC () const |
operator QDate () const | |
operator QDateTime () const | |
operator QTime () const | |
bool | operator!= (const TimeStamp &ts) const |
bool | operator< (const TimeStamp &ts) const |
bool | operator<= (const TimeStamp &ts) const |
TimeStamp & | operator= (const TimeStamp &) |
bool | operator== (const TimeStamp &ts) const |
bool | operator> (const TimeStamp &ts) const |
bool | operator>= (const TimeStamp &ts) const |
quint8 | second () const |
void | setLocal () |
void | setUTC () |
bool | setZone (QString) |
QDate | toDate () const |
QDateTime | toDateTime () const |
QString | toISO () const |
TimeStamp | toLocal () const |
QDateTime | toSystemDateTime () const |
QDateTime | toSystemDateTimeUTC () const |
QTime | toTime () const |
qint64 | toUnix () const |
TimeStamp | toUTC () const |
TimeStamp | toZone (QString zone) const |
WeekDay | weekDay () const |
qint16 | year () const |
QString | zone () const |
QString | zoneAbbreviation () const |
TimeZoneLib::TZFile | zoneFile () const |
returns an instance of this time stamp's current zone file (or one that represents just the UTC-offset if there is none) More... | |
Static Public Member Functions | |
static QString | defaultZone () |
static TimeZoneLib::TZFile | defaultZoneFile () |
returns a copy of the default zone file More... | |
static void | forgetDefaultZone () |
static TimeStamp | fromDate (int year, quint8 month, quint8 day, bool isLocal=true) |
static TimeStamp | fromDate (QDate dt, bool isLocal=true) |
static TimeStamp | fromDate (int year, quint8 month, quint8 day, QString zone) |
static TimeStamp | fromDate (QDate dt, QString zone) |
static TimeStamp | fromDateTime (QDateTime dt) |
static TimeStamp | fromDateTime (QDateTime dt, bool isLocal) |
static TimeStamp | fromDateTime (QDateTime dt, QString zone) |
static TimeStamp | fromDateTime (QDate dt, QTime tm) |
static TimeStamp | fromDateTime (QDate dt, QTime tm, bool isLocal) |
static TimeStamp | fromDateTime (QDate dt, QTime tm, QString zone) |
static TimeStamp | fromDateTime (int year, quint8 month, quint8 day, quint8 hour, quint8 minute, bool isLocal=true) |
static TimeStamp | fromDateTime (int year, quint8 month, quint8 day, quint8 hour, quint8 minute, quint8 second, bool isLocal=true) |
static TimeStamp | fromTime (quint8 hour, quint8 minute, bool isLocal=true) |
static TimeStamp | fromTime (quint8 hour, quint8 minute, quint8 second, bool isLocal=true) |
static TimeStamp | fromTime (quint8 hour, quint8 minute, QString zone) |
static TimeStamp | fromTime (quint8 hour, quint8 minute, quint8 second, QString zone) |
static TimeStamp | fromTime (QTime tm, bool isLocal=true) |
static TimeStamp | fromTime (QTime tm, QString zone) |
static bool | loadZone (QString zone) |
static TimeStamp | now (QString zone) |
static TimeStamp | now (bool isLocal=true) |
static void | resetRepository () |
static bool | setDefaultZone (QString zone) |
static void | setSearchPath (const QStringList &) |
static void | storeDefaultZone () |
static QString | systemLocalZone () |
static TimeZoneLib::TZFile | systemLocalZoneFile () |
returns a copy of the system local zone file More... | |
represents the TZ's idea of a time stamp - it uses time zone names in the Olsen notation (eg. "Europe/Berlin")
This class always calculates according to the Gregorian calendar, even for dates preceding its introduction (1582 in most western regions, even after 1900 in some localities).
Valid time zones are strings of the form "Region/City", these are mapped to file names relative to the repository. Zones are checked for invalid characters before being accepted, invalid zones are generally replaced by UTC.
Warning: at the moment this class is not thread safe!
enum TimeStamp::WeekDay |
TimeStamp::TimeStamp | ( | ) |
creates a zero timestamp (it matches Epoch and resides on the UTC zone)
References initDefault().
creates a timestamp from a unix time
ts | the unix timestamp to use |
isLocal | whether the default time zone should be used, true per default |
References defaultzone, and initDefault().
TimeStamp::TimeStamp | ( | qint64 | ts, |
QString | zone | ||
) |
creates a timestamp from a unix time
ts | the unix timestamp to use |
zone | the zone it will reside on initially, if the zone is not found it will use UTC instead |
References initDefault().
creates a timestamp from a unix time
ts | the unix timestamp to use |
msec | the milli-seconds beyond that timestamp |
isLocal | whether the default time zone should be used, true per default |
References defaultzone, and initDefault().
TimeStamp::TimeStamp | ( | qint64 | ts, |
quint16 | msec, | ||
QString | zone | ||
) |
creates a timestamp from a unix time
ts | the unix timestamp to use |
msec | the milli-seconds beyond that timestamp |
zone | the zone it will reside on initially, if the zone is not found it will use UTC instead |
References initDefault().
creates a timestamp from a QDate, the internal time is set to 0:00:00.000, per default assumes local time
References defaultzone, and initDefault().
TimeStamp::TimeStamp | ( | const QDate & | dt, |
QString | zone | ||
) |
creates a timestamp from a QDate assuming it to represent midnight on the given time zone
References initDefault().
creates a timestamp from a QTime, using today as date, per default assumes that the time is local - if the default time zone differs from the system time zone this may lead to misinterpretations
References defaultzone, and initDefault().
TimeStamp::TimeStamp | ( | const QTime & | tm, |
QString | z | ||
) |
creates a timestamp from QTime, using today on the given time zone as date, the timestamp is local to the given time zone
References initDefault().
TimeStamp::TimeStamp | ( | const QDateTime & | ts | ) |
creates a timestamp from QDateTime, it converts the QDateTime object to UTC before assigning it, most QDateTime objects created without specifying an explicit time zone are assigned local time by Qt; if the timestamp was of local time the timestamp then moves to the default zone, this may or may not match the zone set by the system, so the resulting timestamp may show time for a different zone
ts | timestamp to be converted |
References defaultzone, and initDefault().
TimeStamp::TimeStamp | ( | const QDateTime & | ts, |
bool | isLocal | ||
) |
creates a timestamp from QDateTime, it ignores the settings of the ts object and uses isLocal to convert it into a UTC based timestamp
ts | timestamp to be converted |
isLocal | if set to true the timestamp is interpreted to be of the default time zone |
References defaultzone, initDefault(), and tm.
TimeStamp::TimeStamp | ( | const QDateTime & | ts, |
QString | zone | ||
) |
creates a timestamp from QDateTime, the settings of the ts object are ignored and it is interpreted to be in the given time zone
ts | timestamp to be converted |
zone | the time zone this QDateTime is interpreted to represent, if it does not exist it is interpreted to be UTC |
References initDefault(), and tm.
TimeStamp::TimeStamp | ( | const TimeStamp & | t | ) |
copies a timestamp
void TimeStamp::addDays | ( | int | d | ) |
adds d days to this timestamp
References TimeZoneLib::SecondsPerDay.
void TimeStamp::addMSecs | ( | int | msec | ) |
adds msec milli-seconds to this timestamp
References TimeZoneLib::fdiv(), and TimeZoneLib::pmod().
void TimeStamp::addSecs | ( | int | sec | ) |
adds sec seconds to this timestamp
|
inline |
returns the day of month of this timestamp according to its own zone
|
static |
returns the name of the current default time zone; returns "UTC" as a fallback
References defaultzone, and initDefault().
|
static |
returns a copy of the default zone file
References defaultzone, and TimeZoneLib::getRegistryZone().
|
static |
makes the app forget its default configuration (next time setDefaultZone is called with an empty string it will guess again)
|
inlinestatic |
convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00
convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00
|
inlinestatic |
convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00
|
inlinestatic |
convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local date and time
|
inlinestatic |
convenience function: constructs a timestamp from a specific local time of today
|
inlinestatic |
convenience function: constructs a timestamp from a specific local time of today
|
inlinestatic |
convenience function: constructs a timestamp from a specific local time of today
|
inlinestatic |
convenience function: constructs a timestamp from a specific local time of today
convenience function: constructs a timestamp from a specific local time of today
|
inlinestatic |
convenience function: constructs a timestamp from a specific local time of today
|
inline |
returns the hour of this timestamp according to its own zone
|
static |
Tries to load the given zone, returns true on success. Other than loading it this method does not do anything with the loaded zone, it just checks that it is available to time stamps.
References TimeZoneLib::getRegistryZone(), and TimeZoneLib::TZFile::isValid().
|
inline |
returns the minute of this timestamp according to its own zone
|
inline |
returns the month of this timestamp according to its own zone
|
inline |
move the timezone of this object to the default timezone; this is a shortcut for moveToZone(defaultZone())
|
inline |
move the timezone of this object to UTC; this is a shortcut for moveToZone("UTC")
bool TimeStamp::moveToZone | ( | QString | z | ) |
moves the timezone that this object represents, returns true on success, false if the timezone was not found - in the latter case it moves to UTC
This method preserves the time as numerical values, so if the new zone has a different offset from UTC the object will represent a different point in time after the conversion. For example, if the time stamp is currently set to UTC "2010-07-06 12:11:22.000 +00:00" and is moved to "Europe/Berlin" it will now represent "2010-07-06 12:11:22.000 +02:00" or an actualy time two hours earlier.
References TimeZoneLib::dateTime2stamp(), TimeZoneLib::getRegistryZone(), TimeZoneLib::TZFile::name(), TimeZoneLib::TZRule::offsetFromUTC(), and TimeZoneLib::TZFile::ruleForLocalTime().
|
inline |
returns the milli-second of this timestamp
|
inlinestatic |
returns the current date/time as localized time stamps
zone | the name of the target time zone |
returns the current date/time as time stamp
isLocal | if true the timestamp will be in the default time zone, if false on UTC |
|
inline |
returns the offset from UTC of this timestamp, positive values are east of UTC
|
inline |
converts the timestamp to QDate according to its own timezone
|
inline |
converts the timestamp to QDateTime according to its own timezone, if the internal timezone is not UTC it will mark the resulting QDateTime as Qt::OffsetFromUTC unfortunately Qt has no way of storing the exact offset, so you have to remember it yourself
|
inline |
converts the timestamp to QTime according to its own timezone
returns true if those two timestamps represent differnt times, regardless of time zone, eg. UTC 10:00 will be regarded as different from to 10:00 UTC+02:00
returns true if this timestamp represents an earlier time than the argument
returns true if this timestamp is earlier or equivalent to the argument
returns true if those two timestamps represent the same time, regardless of time zone, eg. UTC 10:00 will be regarded as equivalent to 12:00 UTC+02:00
returns true if this timestamp represents a later time than the argument
returns true if this timestamp is later or equivalent to the argument
|
static |
resets the internal time zone repository, this forces all time zones to reload, it also tries to reset the default zone - if you changed the search path this may mean that the default zone is reset to UTC
References defaultzone, registry, and TimeZoneLib::TZFile::setName().
Referenced by initDefault().
|
inline |
returns the second of this timestamp according to its own zone
|
static |
sets the default time zone - all objects that are created as "local" are regarded to be in this time zone, initially the system tries to guess what the system local time zone is; if setting fails the default will be UTC afterwards
zone | the Olsen name of the local zone, "UTC" will set the local zone to UTC, an empty string will try to guess the system default |
References defaultzone, TimeZoneLib::TZFile::isValid(), registry, TimeZoneLib::TZFile::setName(), TimeZoneLib::systemDefaultDiscover(), and zoneRegExp.
Referenced by initDefault().
|
inline |
sets the timezone of this object to the default time zone; the object will still reprsent the same point in time, but expressed relative to the default time zone; this is a shortcut for setZone(defaultZone())
|
static |
sets the global search repository for time zones, this only affects time zones that have not been loaded yet
References TimeZoneLib::TZFile::setSearchPath().
|
inline |
resets the object to UTC; it will still represent the same point in time, but expressed relative to UTC; this is a shortcut for setZone("UTC")
bool TimeStamp::setZone | ( | QString | z | ) |
sets the timezone that this object represents, returns true on success, false if the timezone was not found - in the latter case it reverts to UTC
the time the object represents will correspond to the same time in UTC before and after the conversion
References TimeZoneLib::getRegistryZone(), TimeZoneLib::TZFile::name(), TimeZoneLib::TZRule::offsetFromUTC(), and TimeZoneLib::TZFile::ruleForTime().
|
static |
stores the current default time zone in the apps configuration (via QSettings), so this is always used instead of guessing
References defaultzone, and initDefault().
|
static |
Tries to find the computers local time zone and returns it
References defaultzone.
|
static |
returns a copy of the system local zone file
References TimeZoneLib::getRegistryZone().
|
inline |
converts the timestamp to QDate according to its own timezone
QDateTime TimeStamp::toDateTime | ( | ) | const |
converts the timestamp to QDateTime according to its own timezone, if the internal timezone is not UTC it will mark the resulting QDateTime as Qt::OffsetFromUTC unfortunately Qt has no way of storing the exact offset, so you have to remember it yourself
QString TimeStamp::toISO | ( | ) | const |
returns the time stamp as ISO date/time string
|
inline |
returns an object that represents the same timestamp in the default time zone
|
inline |
converts this timestamp to a QDateTime that uses the system local time; this is done by converting to UTC first and then letting the operating system convert to its own zone
|
inline |
converts this timestamp to a QDateTime that uses UTC
|
inline |
converts the timestamp to QTime according to its own timezone
|
inline |
returns the unix timestamp
|
inline |
returns an object that represents the same timestamp in UTC
|
inline |
returns an object that represents the same timestamp in the specified time zone, or UTC if the time zone is not valid
TimeStamp::WeekDay TimeStamp::weekDay | ( | ) | const |
returns the day of the week
References TimeZoneLib::weekDayOf().
|
inline |
returns the year of this timestamp according to its own zone
|
inline |
returns the currently set time zone or "UTC" if it has none
QString TimeStamp::zoneAbbreviation | ( | ) | const |
returns the abbreviated time zone name (not guaranteed to be globally unique)
References TimeZoneLib::TZRule::abbreviation(), TimeZoneLib::getRegistryZone(), and TimeZoneLib::TZFile::ruleForTime().
TimeZoneLib::TZFile TimeStamp::zoneFile | ( | ) | const |
returns an instance of this time stamp's current zone file (or one that represents just the UTC-offset if there is none)
References TimeZoneLib::getRegistryZone().