Qore Programming Language Reference Manual 0.8.12.8
Basic Data Types
|Boolean||True or False value||True||False|
|String||A sequence of characters with a character encoding||Empty string (i.e. |
|Integer||A 64-bit signed integer|
|Float||A double-precision floating-point number|
|Number||An arbitrary-precision number|
|Date||absolute (with an associated time zone) or relative date/time values, both with resolution to the microsecond|
|Binary||An opaque binary object||an empty object of size 0|
|NULL||Corresponds to a ||Qore::NULL||Qore::NULL|
|NOTHING||Represents the state of a variable having no value or function returning no value (not equivalent to NULL)||Qore::NOTHING||Qore::NOTHING|
LANGenvironment variable (see Environment Variables). If neither of these variables is set, then all strings will be assumed to have
"this is a string"
"n"to it, designating a "number" value.
Absolute date/time values specify a specific point in time in a certain time zone, such as January 1, 2005 10:35:00 +01:00. They are stored interally as a 64-bit signed offset from the Qore epoch (
1970-01-01Z), a non-negative 4-byte integer for microseconds, and a pointer to a time zone description object that provides the UTC offset and daylight savings time information (see Time Zone Handling for more information). Note that all absolute date/time values in Qore are stored internally in UTC and are converted for display purposes to the representation of wall time in their tagged time zone.
Absolute date/time values can be specified with a syntax based on ISO-8601 date formats as follows:
Note that if no time zone information is given, the local time zone will be assumed. If a time zone UTC offset is given, it is given in units of time east of UTC (i.e.
+05:00 means five hours east of UTC).
Or an alternative format (with a
'-' instead of a
'T' to separate the time component):
for example, for just the date without a time component (assumed to be midnight on the given date in the local time zone):
for just the date in UTC, without a time component:
or, for just the time, without a date component (note that in this case the date component will be set to Jan 1, 1970, in order for time arithmetic to function properly and will also be tagged with the local time zone):
Some further examples (note that the date/time values without a time zone specification here are tagged with the local time zone):
The year must be a four-digit number, and all other values except microseconds must be two-digit numbers. If microseconds are present, at least one and up to 6 digits may be given after the decimal point. Pad the numbers with leading zeros if the numbers are smaller than the required number of digits. The hour component must be in 24-hour time format. Except for the month and day values, all other values start with 0 (hour = 00 - 23, minute and second: 00 - 59). Any deviation from this format will cause a parse exception.
When a date/time value is converted to an integer or vice-versa, a 64-bit offset in seconds from the start of the "epoch" is used for the conversion. Qore's "zero date" (the start of Qore's "epoch") is January 1, 1970 UTC. When calculating second offsets from this date, a 64-bit integer is used.
Relative dates (durations) are normally used for date addition and subtraction. See Date/Time Arithmetic for more information.
Internally, durations are stored as a set of seven discrete signed integer values, one each for years, months, days, hours, minutes, seconds, and microseconds.
There are 3 different formats understood by the Qore parser for describing literal durations in Qore as follows:
P3DT21H; based on ISO-8601)
P0001-03-00T00:00:04; based on ISO-8601)
A single relative date/time value (or a duration) may be specified as follows (note that this format is specific to Qore and not based on ISO-8601):
<integer><date component specifier>
250ms: 250 milliseconds
30s: 30 seconds
2m: 2 minutes
Such values are recommended to give to functions and methods taking a timeout value as the units are then clear in the source code (whereas if an integer is given, it may not be clear that the function or method expects a value in milliseconds, for example); for example:
is clearer than the alternative with an argument given as a value in implied milliseconds to the Queue::pop() method:
Date Specifiers For Single Values For Relative Dates (non-ISO-8601 syntax)
This and the next duration format for composite relative date/time values are both based on ISO-8601.
This first format has the following syntax:
Each element above is optional, but at least one element must be present. Note that
"M" means months when before the
"T" and minutes when found after the
"T". The other elements are years, days, hours, seconds, and, as an extension to ISO-8601,
"u" for microseconds. Additionally, the values may be negative.
Here are some examples (using qore's -X command-line option to evaluate and expression and print out the result):
"u"charater is a Qore-specific extension to ISO-8601
The second ISO-8601-based format for specifing complex durations with multiple time units has the following syntax:
This format is more limited than the first format, in that all values must be non-negative, and furthermore, all values must be present (although they may be zero).
Here are some examples of the second format (equivalent to the first examples):
Comparisons with two relative date/time values are made with normalized representations of each component of the date/time value. Because the actual value of a relative date/time value only makes sense when used with an absolute date value (ex: adding
1M to an absolute date value will result in a different number of days being added depending on the month and day of the absolute date value operand), comparisons of relative date/time values with mixed day, month, and year components must be based on approximations. When mixing day, month, and year components, the following approximations are used:
These assumptions try to make sense of expressions like:
45D > 1M
for example. Month lengths can range from 28 to 31 days, therefore while the expression:
30D < 1M
NULLvalue and can only be accessed directly as an immediate value with the constant Qore::NULL. Note that Qore::NULL is not equivalent to NOTHING.
prompt% qore -X 'exists NOTHING' False
Boolean, string, integer, date, floating point, and arbitrary-percision numeric data types can be freely converted from one type to the other, although data loss is possible depending on the conversion (particularly when converting to the boolan type as only two possible values are supported).
When date types are converted from strings, any of the following formats can be used:
"YYYY-MM-DDTHH:mm:SS[.us][Z|+-HH[:MM[:SS]]]", and most reasonable combinations thereof. If the time zone component is missing, then the local time zone will be assumed (see Time Zone Handling).
When dates are converted to and from integer, floating-point, and arbitrary-percision numeric values, the a 64-bit second offset from January 1, 1970 in the local time zone is used for the conversion. For example
1136073600 (regardless of the local time zone the date is in). This is for backwards-compatibility with Qore before time zone support was available; to get the second offset of a date from
1970-01-01Z (i.e. the true epoch offset), call get_epoch_seconds() instead.
When an expression requires a certain data type and the source data type cannot be converted to the desired data type, the default value for the desired data type will be used. The default values are given in Basic Data Types.