declare let process ; const zeroPadding = '000000000' ; let useHrTime = false ; export function useProcessHrtime ( use ) { if ( ! process . env . ROLLUP_BROWSER ) { return ( useHrTime = use && process && typeof process . hrtime === 'function' ) ; } else { return false ; } } useProcessHrtime ( true ) ; let startHrMillis = undefined ; let startHrTime = undefined ; let lastMillis = Date . now ( ) ; let stepsInMillis = 0 ; function nanos ( ) { if ( ! process . env . ROLLUP_BROWSER && useHrTime ) { const hrTime = process . hrtime ( ) as [ number , number ] ; let millis = Date . now ( ) ; if ( ! startHrTime ) { startHrTime = hrTime ; startHrMillis = millis ; } else { hrTime [ 0 ] = hrTime [ 0 ] - startHrTime [ 0 ] ; hrTime [ 1 ] = hrTime [ 1 ] - startHrTime [ 1 ] ; if ( hrTime [ 1 ] < 0 ) { hrTime [ 0 ] -= 1 ; hrTime [ 1 ] += 1000000000 ; } millis = ( startHrMillis as number ) + hrTime [ 0 ] * 1000 + Math . floor ( hrTime [ 1 ] / 1000000 ) ; } const nanos = String ( hrTime [ 1 ] % 1000000 ) ; return String ( millis ) + zeroPadding . substr ( 0 , 6 - nanos . length ) + nanos ; } else { const millis = Date . now ( ) ; if ( millis !== lastMillis ) { lastMillis = millis ; stepsInMillis = 0 ; } else { stepsInMillis ++ ; } const nanos = String ( stepsInMillis ) ; return String ( millis ) + zeroPadding . substr ( 0 , 6 - nanos . length ) + nanos ; } } function micros ( ) { if ( ! process . env . ROLLUP_BROWSER && useHrTime ) { const hrTime = process . hrtime ( ) as [ number , number ] ; const micros = String ( Math . trunc ( hrTime [ 1 ] / 1000 ) % 1000 ) ; return ( String ( Date . now ( ) ) + zeroPadding . substr ( 0 , 3 - micros . length ) + micros ) ; } else { return String ( Date . now ( ) ) + zeroPadding . substr ( 0 , 3 ) ; } } function millis ( ) { return String ( Date . now ( ) ) ; } function seconds ( ) { return String ( Math . floor ( Date . now ( ) / 1000 ) ) ; } /**
 * Exposes functions that creates strings that represent a timestamp that
 * can be used in the line protocol. Micro and nano timestamps are emulated
 * depending on the js platform in use.
 */ export const currentTime = { s : seconds as ( ) => string , ms : millis as ( ) => string , us : micros as ( ) => string , ns : nanos as ( ) => string , seconds : seconds as ( ) => string , millis : millis as ( ) => string , micros : micros as ( ) => string , nanos : nanos as ( ) => string , } ; /**
 * dateToProtocolTimestamp provides converters for JavaScript Date to InfluxDB Write Protocol Timestamp. Keys are supported precisions.
 */ export const dateToProtocolTimestamp = { s : ( d ) : string => `${ Math . floor ( d . getTime ( ) / 1000 ) }` , ms : ( d ) : string => `${ d . getTime ( ) }` , us : ( d ) : string => `${ d . getTime ( ) }000` , ns : ( d ) : string => `${ d . getTime ( ) }000000` , } ; param value returns export function convertTimeToNanos ( value ) { if ( value === undefined ) { return nanos ( ) ; } else if ( typeof value === 'string' ) { return value . length > 0 ? value : undefined ; } else if ( value instanceof Date ) { return `${ value . getTime ( ) }000000` ; } else if ( typeof value === 'number' ) { return String ( Math . floor ( value ) ) ; } else { return String ( value ) ; } }