Qore Programming Language Reference Manual: <date> Class Reference

Qore Programming Language Reference Manual 0.8.11

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | List of all members
<date> Class Reference

Methods in this pseudo-class can be executed on date/time value types. More...

Inheritance diagram for Qore::<date>:
[legend]

## Public Member Functions
bool | absolute ()
| Returns True if the date is an absolute date/time value. More...
*string | currentZoneName ()
| Returns the name of the current time zone for the current absolute date/time value (ex: `"CEST"` for Central European Summer Time for a time during summer time or `"CET"` for Central European Time for the same time zone while daylight savings time is not active) or a UTC offset (like `"+01"`) or `"UTC"` or NOTHING for relative date/time values. More...
int | days ()
| Returns an integer corresponding to the literal day value in the date (does not calculate a duration) More...
int | durationMicroseconds ()
| Returns an integer value representing the the number of microseconds of time duration in the date value (can be either a relative or absolute date) More...
int | durationMilliseconds ()
| Returns an integer value representing the the number of milliseconds of time duration in the date value (can be either a relative or absolute date) More...
int | durationSeconds ()
| Returns an integer value representing the the number of seconds of time duration in the date value (can be either a relative or absolute date) More...
string | format (string format)
| Returns a formatted string for the date value. More...
int | getEpochSeconds ()
| Returns the number of seconds since the start of the epoch (1970-01-01Z) for the current date for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values. More...
int | getEpochSecondsLocalTime ()
| Returns the number of seconds since the start of the epoch (1970-01-01) for the current date in the local time zone for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values. More...
int | getUtcOffset ()
| Returns the time zone offset for the current time in seconds east of UTC or -1 for relative date/time values. More...
int | hours ()
| Returns an integer corresponding to the literal hour value in the date (does not calculate a duration) More...
hash | info ()
| Returns a hash of broken-down date/time information for the date (can be either a relative or absolute date) More...
bool | intp ()
| Returns True because date values can be converted to integers. More...
bool | isDst ()
| Returns True if the current date/time value is currently in daylight savings time. More...
int | microseconds ()
| Returns an integer corresponding to the literal microsecond value in the date (does not calculate a duration) More...
date | midnight ()
| Returns midnight on the given date (strips the time component on the new value) More...
int | milliseconds ()
| Returns an integer corresponding to the literal millisecond value in the date (does not calculate a duration) More...
int | minutes ()
| Returns an integer corresponding to the literal minute value in the date (does not calculate a duration) More...
int | months ()
| Returns an integer corresponding to the literal month value in the date (does not calculate a duration) More...
bool | relative ()
| Returns True if the date is a relative date/time value. More...
int | seconds ()
| Returns an integer corresponding to the literal second value in the date (does not calculate a duration) More...
bool | strp ()
| Returns True because boolean values can be converted to strings. More...
int | typeCode ()
| Returns Qore::NT_DATE. More...
bool | val ()
| Returns False if the date value is all zeros, True if not. More...
int | years ()
| Returns an integer corresponding to the literal year value in the date (does not calculate a duration) More...
*TimeZone | zone ()
| Returns a Qore::TimeZone object for the time zone of the date/time value; returns NOTHING for relative date/time values. More...
Public Member Functions inherited from <value>
bool | callp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression is a callable value (ie closures or call references) More...
bool | empty ()
| Returns True; this method will be reimplemented in container types where it may return False. More...
bool | intp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to an integer. More...
AbstractIterator | iterator ()
| Returns an iterator object for the value; the default iterator object returned is SingleValueIterator. More...
int | lsize ()
| Returns 1; the return value of this method should give the list size of the value, which is normally 1 for non-lists (except for NOTHING where the size will be 0) and the number of the elements in the list for lists; this method will be reimplemented in other types where it may return other values. More...
int | size ()
| Returns zero; this method will be reimplemented in container types where it may return a non-zero value. More...
bool | sizep ()
| Returns True if the type can return a non-zero size (True for containers including binary objects and strings, False for everything else) More...
bool | strp ()
| Returns False; this method is reimplemented in other types and will return True if the given expression can be converted to a string. More...
bool | toBool ()
| Returns the boolean representation of the value; the default is False. More...
float | toFloat ()
| Returns the floating-point representation of the value; the default is 0.0. More...
int | toInt ()
| Returns the integer representation of the value; the default is 0. More...
number | toNumber ()
| Returns the arbitrary-precision numeric representation of the value; the default is 0. More...
string | toString ()
| Returns the string representation of the value; the default is an empty string. More...
string | type ()
| Returns the string type for the value. More...
int | typeCode ()
| Returns the type code for the value. More...
bool | val ()
| Returns False; this method is reimplemented in other types and will return True if the given expression has a value that would be converted to True according to the rules described in %perl-bool-eval. More...

## Detailed Description

Methods in this pseudo-class can be executed on date/time value types.

## Member Function Documentation

bool <date>::absolute | ( |  | ) |

Returns True if the date is an absolute date/time value.

Returns
  True if the date is an absolute date/time value

Example:
  my bool $b = $d.absolute();

*string <date>::currentZoneName | ( |  | ) |

Returns the name of the current time zone for the current absolute date/time value (ex: `"CEST"` for Central European Summer Time for a time during summer time or `"CET"` for Central European Time for the same time zone while daylight savings time is not active) or a UTC offset (like `"+01"`) or `"UTC"` or NOTHING for relative date/time values.

Returns
  the name of the current time zone for the current absolute date/time value (ex: `"CEST"` for Central European Summer Time for a time during summer time or `"CET"` for Central European Time for the same time zone while daylight savings time is not active) or a UTC offset (like `"+01"`) or `"UTC"` or NOTHING for relative date/time values

Code Flags:
  CONSTANT

Example:
  my *string $zn = $d.currentZoneName();

int <date>::days | ( |  | ) |

Returns an integer corresponding to the literal day value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal day value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.days();

Note
  equivalent to get_days(date)

int <date>::durationMicroseconds | ( |  | ) |

Returns an integer value representing the the number of microseconds of time duration in the date value (can be either a relative or absolute date)

Returns
  an integer value representing the the number of microseconds in the date value; if the value is a relative date, the value is normalized to microseconds and the integer microseconds value is returned, if the value is an absolute date, the duration in microseconds is calculated from the present time; so if the present time is sent as an argument, 0 is returned, if a future date is used, the number of microseconds from the present time to the future date is returned, if an absolute date in the past is used, also 0 is returned (the pseudo-method does not calculate microsecond differences for absolute dates in the past (for this use Date/Time Arithmetic instead); this function can only return a negative value if passed a relative date/time value

Code Flags:
  CONSTANT

Example:
  my int $us = PT2M15S3u.durationMicroseconds(); # returns 135000003

Note
  - equivalent to get_duration_microseconds()
  - to get the literal microseconds integer value from a date/time value without calculating a duration, use <date>::microseconds()

See Also
  - <date>::durationSeconds()
  - <date>::durationMilliseconds()

Since
  Qore 0.8.7

int <date>::durationMilliseconds | ( |  | ) |

Returns an integer value representing the the number of milliseconds of time duration in the date value (can be either a relative or absolute date)

The duration in milliseconds is calculated and any fractional milliseconds are truncated (no rounding is performed)

Returns
  an integer value representing the the number of milliseconds in the date value; if the value is a relative date, the value is normalized to milliseconds and the integer milliseconds value is returned, if the value is an absolute date, the duration in milliseconds is calculated from the present time; so if the present time is sent as an argument, 0 is returned, if a future date is used, the number of milliseconds from the present time to the future date is returned, if an absolute date in the past is used, also 0 is returned (the pseudo-method does not calculate millisecond differences for absolute dates in the past (for this use Date/Time Arithmetic instead); this function can only return a negative value if passed a relative date/time value

Code Flags:
  CONSTANT

Example:
  my int $us = PT2M15S3u.durationMilliseconds(); # returns 135000

Note
  - equivalent to get_duration_milliseconds()
  - to get the literal milliseconds integer value from a date/time value without calculating a duration, use <date>::milliseconds()

See Also
  - <date>::durationSeconds()
  - <date>::durationMicroseconds()

Since
  Qore 0.8.7

int <date>::durationSeconds | ( |  | ) |

Returns an integer value representing the the number of seconds of time duration in the date value (can be either a relative or absolute date)

The duration in seconds is calculated and any fractional seconds are truncated (no rounding is performed)

Returns
  an integer value representing the the number of seconds in the date value; if the value is a relative date, the value is normalized to seconds and the integer seconds value is returned, if the value is an absolute date, the duration in seconds is calculated from the present time; so if the present time is sent as an argument, 0 is returned, if a future date is used, the number of seconds from the present time to the future date is returned, if an absolute date in the past is used, also 0 is returned (the pseudo-method does not calculate second differences for absolute dates in the past (for this use Date/Time Arithmetic instead); this function can only return a negative value if passed a relative date/time value

Code Flags:
  CONSTANT

Example:
  my int $us = PT2M15S3u.durationSeconds(); # returns 135

Note
  - equivalent to get_duration_seconds()
  - to get the literal seconds integer value from a date/time value without calculating a duration, use <date>::seconds()

See Also
  - <date>::durationMilliseconds()
  - <date>::durationMicroseconds()

Since
  Qore 0.8.7

string <date>::format | ( | string | format | ) |

Returns a formatted string for the date value.

Code Flags:
  CONSTANT

Parameters

  format | a string giving the format for the date; see Date Formatting Codes for more information about this string

Returns
  a formatted string for a date argument passed

Example:
  my string $str = $d.format("Day, Mon D, YYYY-MM-DD HH:mm:SS");

Bug:
  there is no locale support; day and month names and abbreviations are only returned in English

Note
  equivalent to format_date(string, date)

int <date>::getEpochSeconds | ( |  | ) |

Returns the number of seconds since the start of the epoch (1970-01-01Z) for the current date for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values.

Code Flags:
  CONSTANT

Example:
  my int $secs = $d.getEpochSeconds();

Returns
  the number of seconds since the start of the epoch (1970-01-01Z) for the current date for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values

Since
  Qore 0.8.8

int <date>::getEpochSecondsLocalTime | ( |  | ) |

Returns the number of seconds since the start of the epoch (1970-01-01) for the current date in the local time zone for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values.

Code Flags:
  CONSTANT

Example:
  my int $secs = $d.getEpochSecondsLocalTime();

Returns
  the number of seconds since the start of the epoch (1970-01-01) for the current date in the local time zone for ref absolute_dates "absolute date/time values"; returns 0 for relative date/time values

Since
  Qore 0.8.8

int <date>::getUtcOffset | ( |  | ) |

Returns the time zone offset for the current time in seconds east of UTC or -1 for relative date/time values.

Returns
  the time zone offset for the current time in seconds east of UTC or -1 for relative date/time values

Code Flags:
  CONSTANT

Example:
  my int $utcoffset = $d.getUtcOffset();

int <date>::hours | ( |  | ) |

Returns an integer corresponding to the literal hour value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal hour value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.hours();

Note
  equivalent to get_hours(date)

hash <date>::info | ( |  | ) |

Returns a hash of broken-down date/time information for the date (can be either a relative or absolute date)

Code Flags:
  CONSTANT

Example:
  my hash $h = date_info($date);

Returns
  a hash of broken-down date/time information for the given date argument

Note
  equivalent to date_info(date)

Since
  Qore 0.8.8

bool <date>::intp | ( |  | ) |

Returns True because date values can be converted to integers.

Returns
  True because date values can be converted to integers

Code Flags:
  CONSTANT

Example:
  if ($n.intp())
  printf("%y: can be converted to an integer: %d\n", $n, int($n));

bool <date>::isDst | ( |  | ) |

Returns True if the current date/time value is currently in daylight savings time.

Returns
  True if the current date/time value is currently in daylight savings time; always returns False for relative date/time values

Code Flags:
  CONSTANT

Example:
  my bool $b = $d.isDst();

int <date>::microseconds | ( |  | ) |

Returns an integer corresponding to the literal microsecond value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal microsecond value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.microseconds();

Note
  - equivalent to get_microseconds(date)
  - to get the number of microseconds of duration in a date/time value, use <date>::durationMicroseconds() instead

date <date>::midnight | ( |  | ) |

Returns midnight on the given date (strips the time component on the new value)

Returns
  midnight on the given date (strips the time component on the new value)

Code Flags:
  CONSTANT

Example:
  my date $midnight = $dt.midnight();

Note
  equivalent to get_midnight()

Since
  Qore 0.8.5

int <date>::milliseconds | ( |  | ) |

Returns an integer corresponding to the literal millisecond value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal millisecond value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.milliseconds();

Note
  - equivalent to get_milliseconds(date)
  - to get the number of milliseconds of duration in a date/time value, use <date>::durationMilliseconds() instead

int <date>::minutes | ( |  | ) |

Returns an integer corresponding to the literal minute value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal minute value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.minutes();

Note
  equivalent to get_minutes(date)

int <date>::months | ( |  | ) |

Returns an integer corresponding to the literal month value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal month value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.months();

Note
  equivalent to get_months(date)

bool <date>::relative | ( |  | ) |

Returns True if the date is a relative date/time value.

Returns
  True if the date is a relative date/time value

Example:
  my bool $b = $d.relative();

int <date>::seconds | ( |  | ) |

Returns an integer corresponding to the literal second value in the date (does not calculate a duration)

The date value can be either a relative or absolute date.

Returns
  an integer corresponding to the literal second value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.seconds();

Note
  - equivalent to get_seconds(date)
  - to get the number of seconds of duration in a date/time value, use <date>::durationSeconds() instead

bool <date>::strp | ( |  | ) |

Returns True because boolean values can be converted to strings.

Returns
  True because boolean values can be converted to strings

Code Flags:
  CONSTANT

Example:
  if ($n.strp())
  printf("%y: can be converted to a string: '%s'\n", $n, string($n));

int <date>::typeCode | ( |  | ) |

Returns Qore::NT_DATE.

Returns
  Qore::NT_DATE

Example:
  switch ($d.typeCode()) {
  case NT_DATE:
  printf("%y: is a date\n", $d);
  break;
  }

bool <date>::val | ( |  | ) |

Returns False if the date value is all zeros, True if not.

Returns
  False if the date value is all zeros, True if not

Code Flags:
  CONSTANT

Example:
  my bool $b = $d.val();

See Also
  - %perl-bool-eval
  - %strict-bool-eval

int <date>::years | ( |  | ) |

Returns an integer corresponding to the literal year value in the date (does not calculate a duration)

Returns
  an integer corresponding to the literal year value in the date (does not calculate a duration)

Code Flags:
  CONSTANT

Example:
  my int $n = $d.years();

Note
  equivalent to get_years(date)

*TimeZone <date>::zone | ( |  | ) |

Returns a Qore::TimeZone object for the time zone of the date/time value; returns NOTHING for relative date/time values.

Returns
  a Qore::TimeZone object for the time zone of the date/time value; returns NOTHING for relative date/time values

Code Flags:
  CONSTANT

Example:
  my *TimeZone $zone = $d.zone();