TZ-Lib  $VERSION$
TimeStamp Class Reference

#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
 
TimeStampoperator= (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...
 

Detailed Description

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!

Member Enumeration Documentation

numerical constants for week days

Enumerator
Sunday 
Monday 
Tuesday 
Wednesday 
Thursday 
Friday 
Saturday 

Constructor & Destructor Documentation

TimeStamp::TimeStamp ( )

creates a zero timestamp (it matches Epoch and resides on the UTC zone)

References initDefault().

TimeStamp::TimeStamp ( qint64  ts,
bool  isLocal = true 
)

creates a timestamp from a unix time

Parameters
tsthe unix timestamp to use
isLocalwhether 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

Parameters
tsthe unix timestamp to use
zonethe zone it will reside on initially, if the zone is not found it will use UTC instead

References initDefault().

TimeStamp::TimeStamp ( qint64  ts,
quint16  msec,
bool  isLocal = true 
)

creates a timestamp from a unix time

Parameters
tsthe unix timestamp to use
msecthe milli-seconds beyond that timestamp
isLocalwhether 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

Parameters
tsthe unix timestamp to use
msecthe milli-seconds beyond that timestamp
zonethe zone it will reside on initially, if the zone is not found it will use UTC instead

References initDefault().

TimeStamp::TimeStamp ( const QDate &  dt,
bool  isLocal = true 
)

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

TimeStamp::TimeStamp ( const QTime &  tm,
bool  isLocal = true 
)

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

Parameters
tstimestamp 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

Parameters
tstimestamp to be converted
isLocalif 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

Parameters
tstimestamp to be converted
zonethe 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

Member Function Documentation

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

quint8 TimeStamp::day ( ) const
inline

returns the day of month of this timestamp according to its own zone

QString TimeStamp::defaultZone ( )
static

returns the name of the current default time zone; returns "UTC" as a fallback

References defaultzone, and initDefault().

TimeZoneLib::TZFile TimeStamp::defaultZoneFile ( )
static

returns a copy of the default zone file

References defaultzone, and TimeZoneLib::getRegistryZone().

void TimeStamp::forgetDefaultZone ( )
static

makes the app forget its default configuration (next time setDefaultZone is called with an empty string it will guess again)

static TimeStamp TimeStamp::fromDate ( int  year,
quint8  month,
quint8  day,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00

static TimeStamp TimeStamp::fromDate ( QDate  dt,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00

static TimeStamp TimeStamp::fromDate ( int  year,
quint8  month,
quint8  day,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00

static TimeStamp TimeStamp::fromDate ( QDate  dt,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific date, sets the time to 0:00:00

static TimeStamp TimeStamp::fromDateTime ( QDateTime  dt)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( QDateTime  dt,
bool  isLocal 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( QDateTime  dt,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( QDate  dt,
QTime  tm 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( QDate  dt,
QTime  tm,
bool  isLocal 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( QDate  dt,
QTime  tm,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( int  year,
quint8  month,
quint8  day,
quint8  hour,
quint8  minute,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromDateTime ( int  year,
quint8  month,
quint8  day,
quint8  hour,
quint8  minute,
quint8  second,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific local date and time

static TimeStamp TimeStamp::fromTime ( quint8  hour,
quint8  minute,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

static TimeStamp TimeStamp::fromTime ( quint8  hour,
quint8  minute,
quint8  second,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

static TimeStamp TimeStamp::fromTime ( quint8  hour,
quint8  minute,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

static TimeStamp TimeStamp::fromTime ( quint8  hour,
quint8  minute,
quint8  second,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

static TimeStamp TimeStamp::fromTime ( QTime  tm,
bool  isLocal = true 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

static TimeStamp TimeStamp::fromTime ( QTime  tm,
QString  zone 
)
inlinestatic

convenience function: constructs a timestamp from a specific local time of today

quint8 TimeStamp::hour ( ) const
inline

returns the hour of this timestamp according to its own zone

bool TimeStamp::loadZone ( QString  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().

quint8 TimeStamp::minute ( ) const
inline

returns the minute of this timestamp according to its own zone

quint8 TimeStamp::month ( ) const
inline

returns the month of this timestamp according to its own zone

void TimeStamp::moveToLocal ( )
inline

move the timezone of this object to the default timezone; this is a shortcut for moveToZone(defaultZone())

void TimeStamp::moveToUTC ( )
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().

quint16 TimeStamp::msecs ( ) const
inline

returns the milli-second of this timestamp

static TimeStamp TimeStamp::now ( QString  zone)
inlinestatic

returns the current date/time as localized time stamps

Parameters
zonethe name of the target time zone
static TimeStamp TimeStamp::now ( bool  isLocal = true)
inlinestatic

returns the current date/time as time stamp

Parameters
isLocalif true the timestamp will be in the default time zone, if false on UTC
qint32 TimeStamp::offsetFromUTC ( ) const
inline

returns the offset from UTC of this timestamp, positive values are east of UTC

TimeStamp::operator QDate ( ) const
inline

converts the timestamp to QDate according to its own timezone

TimeStamp::operator QDateTime ( ) const
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

TimeStamp::operator QTime ( ) const
inline

converts the timestamp to QTime according to its own timezone

bool TimeStamp::operator!= ( const TimeStamp ts) const
inline

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

bool TimeStamp::operator< ( const TimeStamp ts) const
inline

returns true if this timestamp represents an earlier time than the argument

bool TimeStamp::operator<= ( const TimeStamp ts) const
inline

returns true if this timestamp is earlier or equivalent to the argument

TimeStamp & TimeStamp::operator= ( const TimeStamp t)

copies a timestamp

bool TimeStamp::operator== ( const TimeStamp ts) const
inline

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

bool TimeStamp::operator> ( const TimeStamp ts) const
inline

returns true if this timestamp represents a later time than the argument

bool TimeStamp::operator>= ( const TimeStamp ts) const
inline

returns true if this timestamp is later or equivalent to the argument

void TimeStamp::resetRepository ( )
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().

quint8 TimeStamp::second ( ) const
inline

returns the second of this timestamp according to its own zone

bool TimeStamp::setDefaultZone ( QString  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

Returns
true if the new zone is valid, otherwise resets the local zone to UTC
Parameters
zonethe 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().

void TimeStamp::setLocal ( )
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())

void TimeStamp::setSearchPath ( const QStringList &  s)
static

sets the global search repository for time zones, this only affects time zones that have not been loaded yet

References TimeZoneLib::TZFile::setSearchPath().

void TimeStamp::setUTC ( )
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().

void TimeStamp::storeDefaultZone ( )
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().

QString TimeStamp::systemLocalZone ( )
static

Tries to find the computers local time zone and returns it

References defaultzone.

TimeZoneLib::TZFile TimeStamp::systemLocalZoneFile ( )
static

returns a copy of the system local zone file

References TimeZoneLib::getRegistryZone().

QDate TimeStamp::toDate ( ) const
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

TimeStamp TimeStamp::toLocal ( ) const
inline

returns an object that represents the same timestamp in the default time zone

QDateTime TimeStamp::toSystemDateTime ( ) const
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

QDateTime TimeStamp::toSystemDateTimeUTC ( ) const
inline

converts this timestamp to a QDateTime that uses UTC

QTime TimeStamp::toTime ( ) const
inline

converts the timestamp to QTime according to its own timezone

qint64 TimeStamp::toUnix ( ) const
inline

returns the unix timestamp

TimeStamp TimeStamp::toUTC ( ) const
inline

returns an object that represents the same timestamp in UTC

TimeStamp TimeStamp::toZone ( QString  zone) const
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().

qint16 TimeStamp::year ( ) const
inline

returns the year of this timestamp according to its own zone

QString TimeStamp::zone ( ) const
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().


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