Unit Grijjy.DateUtils

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

System level date/time utilities

Overview

Functions and Procedures

function goDateTimeToMillisecondsSinceEpoch(const AValue: TDateTime; const AInputIsUTC: Boolean): Int64;
function goToDateTimeFromMillisecondsSinceEpoch(const AValue: Int64; const AReturnUTC: Boolean): TDateTime;
function goDateTimeToTicks(const AValue: TDateTime; const AInputIsUTC: Boolean): Int64;
function goDateTimeFromTicks(const AValue: Int64; const AReturnUTC: Boolean): TDateTime;

Constants

MIN_MILLISECONDS_SINCE_EPOCH = -62135596800000;
MAX_MILLISECONDS_SINCE_EPOCH = 253402300799999;

Description

Functions and Procedures

function goDateTimeToMillisecondsSinceEpoch(const AValue: TDateTime; const AInputIsUTC: Boolean): Int64;

Converts a date/time value to a number of milliseconds since the Unix epoch.

Parameters
AValue
the date/time value to convert.
AInputIsUTC
whether AValue is in UTC format.
Returns

The number of milliseconds since the Unix epoch.

function goToDateTimeFromMillisecondsSinceEpoch(const AValue: Int64; const AReturnUTC: Boolean): TDateTime;

Converts a number of milliseconds since the Unix epoch to a date/time value.

Parameters
AValue
number of milliseconds since the Unix epoch.
AReturnUTC
whether to return the corresponding date/time value in local time (False) or universal time (True).
Returns

The date/time value.

Exceptions raised
EArgumentOutOfRangeException
if AValue cannot be accurately converted to a date/time value
function goDateTimeToTicks(const AValue: TDateTime; const AInputIsUTC: Boolean): Int64;

Converts a date/time value to a number of ticks that has passed since midnight, January 1, 0001 UTC.

There are 10,000 ticks in a milliseconds (or 10 million ticks in a second).

Parameters
AValue
the date/time value to convert.
AInputIsUTC
whether AValue is in UTC format.
Returns

The number of ticks.

function goDateTimeFromTicks(const AValue: Int64; const AReturnUTC: Boolean): TDateTime;

Converts a number of ticks that has passed since midnight, January 1, 0001 UTC to a date/time value.

There are 10,000 ticks in a milliseconds (or 10 million ticks in a second).

Parameters
AValue
the number of ticks.
AReturnUTC
whether to return the corresponding date/time value in local time (False) or universal time (True).
Returns

The date/time value.

Constants

MIN_MILLISECONDS_SINCE_EPOCH = -62135596800000;

The minimum and maximum number of milliseconds since the Unix epoch that we can use to convert to and from a TDateTime value without loss in precision. Note that Delphi's TDateTime type can safely handle a larger range of milliseconds, but other languages may not.

MAX_MILLISECONDS_SINCE_EPOCH = 253402300799999;
 

Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26