tai64
Version:
TypeScript implementation of TAI64 timestamps for Node.js and the browser
125 lines (124 loc) • 4.58 kB
TypeScript
/**
* Copyright (c) 2018 hl2, https://hl2.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
declare class TAI64 {
private readonly label;
/**
* Instance of TAI64 representing the second that began 1970 TAI.
*/
static readonly EPOCH: TAI64;
/**
* Return a TAI64 the current number of seconds elapsed since 1970 TAI.
*
* @returns An instance of TAI64
*/
static now(): TAI64;
/**
* Return a TAI64 corresponding to the given UNIX timestamp.
*
* @param timestamp - The UNIX timestamp in seconds
* @returns An instance of TAI64
*/
static fromUnix(timestamp: number): TAI64;
/**
* Return a TAI64 corresponding to the given hexadecimal string representing a TAI64. This method
* is an alias for `TAI64#fromString()` method.
*
* @param hexString - The hexadecimal string
* @returns An instance of TAI64
*/
static fromHexString(hexString: string): TAI64;
/**
* Return a TAI64 corresponding to the given string representing a TAI64 in the given radix.
*
* @param str - The string
* @param radix - An integer that represents the radix (the base in mathematical numeral systems), defaults to `16`
* @returns An instance of TAI64
*/
static fromString(str: string, radix?: number): TAI64;
/**
* Return a TAI64 corresponding to the given byte array representing a TAI64.
*
* @param bytes - The byte array
* @returns An instance of TAI64
*/
static fromByteArray(bytes: number[]): TAI64;
/**
* Construct an instance of TAI64.
*
* @param label - The TAI64 label between 0 and 2^63-1, inclusive
* @returns An instance of TAI64
* @throws RangeError if the given label is not between 0 and 2^63-1, inclusive
*/
private constructor();
/**
* Return if this TAI64 is after the given TAI64.
*
* @param other - The other TAI64 to compare
* @returns `true` if this TAI64 is after the given TAI64, `false` otherwise
*/
isAfter(other: TAI64): boolean;
/**
* Return if this TAI64 is before the given TAI64.
*
* @param other - The other TAI64 to compare
* @returns `true` if this TAI64 is before the given TAI64, `false` otherwise
*/
isBefore(other: TAI64): boolean;
/**
* Return if this TAI64 is equal to the given TAI64.
*
* @param other - The other TAI64 to compare
* @returns `true` if this TAI64 is equal to the given TAI64, `false` otherwise
*/
isEqual(other: TAI64): boolean;
/**
* Compare this TAI64 to the given TAI64.
*
* @param other - The other TAI64 to compare
* @returns
* - `1` if this TAI64 is before the given TAI64
* - `-1` if this TAI64 is before the given TAI64
* - `0` if this TAI64 is equal to the given TAI64
*/
compareTo(other: TAI64): number;
/**
* Return a byte array representation of this TAI64.
*/
toByteArray(): number[];
/**
* Return an hexadecimal string representation of this TAI64. This method
* is an alias for `TAI64#toString()` method.
*/
toHexString(): string;
/**
* Return a string representation of this TAI64.
*
* @param radix - An integer that represents the radix (the base in mathematical numeral systems), defaults to `16`
*/
toString(radix?: number): string;
/**
* Return a UNIX timestamp corresponding to this TAI64.
*/
toUnix(): number;
}
export { TAI64 };