UNPKG

2.66 kBTypeScriptView Raw
1export interface INanoDate extends Date {
2 /**
3 * Returns the unix nanoseconds timestamp as a string.
4 */
5 getNanoTime: () => string;
6 /**
7 * Formats the date as an ISO RFC3339 timestamp with nanosecond precision.
8 */
9 toNanoISOString: () => string;
10}
11export declare type TimePrecision = "n" | "u" | "ms" | "s" | "m" | "h";
12/**
13 * Precision is a map of available Influx time precisions.
14 * @type {Object.<String, String>}
15 * @example
16 * console.log(Precision.Hours); // => 'h'
17 * console.log(Precision.Minutes); // => 'm'
18 * console.log(Precision.Seconds); // => 's'
19 * console.log(Precision.Milliseconds); // => 'ms'
20 * console.log(Precision.Microseconds); // => 'u'
21 * console.log(Precision.Nanoseconds); // => 'n'
22 */
23export declare const Precision: Readonly<{
24 Hours: string;
25 Microseconds: string;
26 Milliseconds: string;
27 Minutes: string;
28 Nanoseconds: string;
29 Seconds: string;
30}>;
31/**
32 * Covers a nanoseconds unix timestamp to a INanoDate for node-influx. The
33 * timestamp is provided as a string to prevent precision loss.
34 *
35 * Please see [A Moment for Times](https://node-influx.github.io/manual/
36 * usage.html#a-moment-for-times) for a more complete and eloquent explanation
37 * of time handling in this module.
38 *
39 * @param timestamp
40 * @example
41 * const date = toNanoDate('1475985480231035600')
42 *
43 * // You can use the returned Date as a normal date:
44 * expect(date.getTime()).to.equal(1475985480231);
45 *
46 * // We decorate it with two additional methods to read
47 * // nanosecond-precision results:
48 * expect(date.getNanoTime()).to.equal('1475985480231035600');
49 * expect(date.toNanoISOString()).to.equal('2016-10-09T03:58:00.231035600Z');
50 */
51export declare function toNanoDate(timestamp: string): INanoDate;
52/**
53 * FormatDate converts the Date instance to Influx's date query format.
54 * @private
55 */
56export declare function formatDate(date: Date): string;
57/**
58 * Converts a Date instance to a timestamp with the specified time precision.
59 * @private
60 */
61export declare function dateToTime(date: Date | INanoDate, precision: TimePrecision): string;
62/**
63 * Converts an ISO-formatted data or unix timestamp to a Date instance. If
64 * the precision is finer than 'ms' the returned value will be a INanoDate.
65 * @private
66 */
67export declare function isoOrTimeToDate(stamp: string | number, precision?: TimePrecision): INanoDate;
68/**
69 * Converts a timestamp to a string with the correct precision. Assumes
70 * that raw number and string instances are already in the correct precision.
71 * @private
72 */
73export declare function castTimestamp(timestamp: string | number | Date, precision: TimePrecision): string;