Qore Programming Language Reference Manual  0.8.9
 All Classes Namespaces Functions Variables Groups Pages
Qore::TimeZone Class Reference

The TimeZone class provides access to time zone functionality. More...

Public Member Functions

int UTCOffset ()
 Returns the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC. More...
 
 constructor (string region)
 Creates the TimeZone object based on the region name (ex: "America/Chicago") More...
 
 constructor (softint seconds_east)
 Creates the TimeZone object based on the number of seconds east of UTC (3600 = UTC +01) More...
 
 copy ()
 Creates a copy of the TimeZone object. More...
 
date date (softint secs, softint us=0)
 Returns the equivalent date in the time zone of the current object. More...
 
date date (date d)
 Returns the equivalent date in the time zone of the current object. More...
 
date date (string dtstr)
 Returns the equivalent date in the time zone of the current object. More...
 
date date (string dtstr, string mask)
 Returns a date/time value in the current TimeZone corresponding to parsing a string argument according to a format mask. More...
 
date dateMs (softint ms)
 Returns a date in the object's zone based on an offsets in milliseconds from 1970-01-01Z. More...
 
date dateUs (softint us)
 Returns a date in the object's zone based on an offsets in microseconds from 1970-01-01Z. More...
 
bool hasDST ()
 Returns True if the zone has daylight saving's time rules, False if not. More...
 
string region ()
 Returns the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00". More...
 

Static Public Member Functions

static TimeZone get ()
 Returns a TimeZone object for the current time zone. More...
 
static nothing set (TimeZone zone)
 Sets the time zone for the current Program object from a TimeZone object. More...
 
static nothing setRegion (string region)
 Sets the time zone for the current Program object from a time zone region name. More...
 
static nothing setUTCOffset (softint seconds_east)
 Sets the time zone for the current Program object from an integer offset in seconds east of UTC. More...
 

Detailed Description

The TimeZone class provides access to time zone functionality.

TimeZone objects based on zoneinfo region files (on UNIX) or registry information (on Windows) can have daylight savings time information; those based on UTC offsets have none.

Member Function Documentation

Qore::TimeZone::constructor ( string  region)

Creates the TimeZone object based on the region name (ex: "America/Chicago")

Parameters
regionThe region name for the time zone (ex: "America/Chicago"); if the zoneinfo file for the region cannot be found or parsed (on UNIX) or if the registry entry cannot be found (on Windows), then an exception is thrown
Note
On Windows the region names correspond to registry entries under HKEY_LOCAL_MACHINE SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones (ex: "Central Europe Standard Time")
Example:
my TimeZone $tz("Europe/Prague");
Exceptions
TZINFO-ERRORUnable to read zoneinfo file; invalid file magic; error parsing zoneinfo file, etc
Qore::TimeZone::constructor ( softint  seconds_east)

Creates the TimeZone object based on the number of seconds east of UTC (3600 = UTC +01)

Parameters
seconds_eastThe number of seconds east of UTC for the time zone; for zones west of UTC, use negative numbers
Example:
my TimeZone $tz(3600);
Qore::TimeZone::copy ( )

Creates a copy of the TimeZone object.

Example:
my TimeZone $newzone = $tz.copy();
date Qore::TimeZone::date ( softint  secs,
softint  us = 0 
)

Returns the equivalent date in the time zone of the current object.

Code Flags:
CONSTANT
Parameters
secsoffset are in seconds from 1970-01-01Z
usoffset are in microseconds from 1970-01-01Z
Example:
my date $dt = $tz.date($secs);
date Qore::TimeZone::date ( date  d)

Returns the equivalent date in the time zone of the current object.

Code Flags:
CONSTANT
Parameters
dA date that will be used to create the date in the time zone of the objects; the same point in time will be returned but in the time zone of the object
Example:
my date $dt = $tz.date(2012-01-01T13:56:23+01:00);
date Qore::TimeZone::date ( string  dtstr)

Returns the equivalent date in the time zone of the current object.

Code Flags:
CONSTANT
Parameters
dtstrThe string to be used to return a date in the object's time zone
Example:
my date $dt = $tz.date("2012-01-01T13:56:23");
Since
Qore 0.8.4
date Qore::TimeZone::date ( string  dtstr,
string  mask 
)

Returns a date/time value in the current TimeZone corresponding to parsing a string argument according to a format mask.

Code Flags:
RET_VALUE_ONLY
Parameters
dtstra string giving a date
maskthe mask for the date value; see Date Mask Format for information on the format of the format mask
Returns
the date/time value in the current TimeZone corresponding to parsing the dtstr string argument according to mask serving as a format mask
Example:
my TimeZone $tz("Europe/London");
printf("%y\n", $tz.date("05/02/2012", "DD/MM/YYYY")); # outputs: 2012-02-05 00:00:00 Sun Z (GMT)
Exceptions
DATE-CONVERT-ERRORinvalid mask specification
See Also
similar to but more useful than Qore::date(string, string)
Since
Qore 0.8.6
date Qore::TimeZone::dateMs ( softint  ms)

Returns a date in the object's zone based on an offsets in milliseconds from 1970-01-01Z.

Code Flags:
CONSTANT
Parameters
msan offsets in milliseconds from 1970-01-01Z
Returns
a date in the object's zone based on the given offsets in milliseconds from 1970-01-01Z
Example:
my date $dt = $tz.dateMs($offset_ms);
date Qore::TimeZone::dateUs ( softint  us)

Returns a date in the object's zone based on an offsets in microseconds from 1970-01-01Z.

Code Flags:
CONSTANT
Parameters
usan offsets in microseconds from 1970-01-01Z
Returns
a date in the object's zone based on the given offsets in microseconds from 1970-01-01Z
Example:
my date $dt = $tz.dateUs($offset_uss);
static TimeZone Qore::TimeZone::get ( )
static

Returns a TimeZone object for the current time zone.

Returns
a TimeZone object for the current time zone
Code Flags:
CONSTANT
Example:
my TimeZone $tz = TimeZone::get();
bool Qore::TimeZone::hasDST ( )

Returns True if the zone has daylight saving's time rules, False if not.

TimeZone objects based on zoneinfo region files (on UNIX) or registry information (on Windows) can have (but do not necessarily have) daylight savings time information; those based on UTC offsets have none

Returns
True if the current zone has daylight saving's time rules, False if not
Code Flags:
CONSTANT
Example:
my bool $hasdst = $tz.hasDST();
string Qore::TimeZone::region ( )

Returns the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00".

Returns
the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00"
Code Flags:
CONSTANT
Example:
my string $region = $tz.region();
static nothing Qore::TimeZone::set ( TimeZone  zone)
static

Sets the time zone for the current Program object from a TimeZone object.

Restrictions:
Qore::PO_NO_LOCALE_CONTROL
Parameters
zonethe time zone to set
Example:
my TimeZone $tz("Europe/Prague");
static nothing Qore::TimeZone::setRegion ( string  region)
static

Sets the time zone for the current Program object from a time zone region name.

Restrictions:
Qore::PO_NO_LOCALE_CONTROL
Parameters
regionthe region name to set
Note
On Windows the region names correspond to registry entries under HKEY_LOCAL_MACHINE SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones (ex: "Central Europe Standard Time)
Example:
TimeZone::setRegion("Europe/Prague");
static nothing Qore::TimeZone::setUTCOffset ( softint  seconds_east)
static

Sets the time zone for the current Program object from an integer offset in seconds east of UTC.

Restrictions:
Qore::PO_NO_LOCALE_CONTROL
Parameters
seconds_eastthe number of seconds east of UTC for the new time zone (negative numbers give seconds west of UTC)
Example:
int Qore::TimeZone::UTCOffset ( )

Returns the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC.

Returns
the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC
Code Flags:
CONSTANT
Example:
my int $offset = $tz.UTCOffset();