Timestamp for 64-bit time_t, nanosecond precision and strftime

author

  Yusuke Kawasaki

license

  MIT

see

  https://github.com/kawanet/timestamp-nano

### Hierarchy

- Timestamp

## Index

### Constructors

- constructor

### Methods

- addNano
- getNano
- getTimeT
- getYear
- toDate
- toJSON
- toString
- writeInt64BE
- writeInt64LE
- fromDate
- fromInt64BE
- fromInt64LE
- fromString
- fromTimeT

## Constructors

### constructor

- new Timestamp(time: number, nano?: number, year?: number): Timestamp

- #### Parameters

  - ##### time: number

    Milliseconds from epoch

  - ##### Optional nano: number

    Offset number for nanosecond precision

  - ##### Optional year: number

    Offset number for year which must be a multiple of 400 to avoid leap year calculation

  #### Returns Timestamp

## Methods

### addNano

- addNano(nano: number): this

- Adds offset in nanosecond precision.

  #### Parameters

  - ##### nano: number

    offset number for nanosecond precision in addition.

  #### Returns this

### getNano

- getNano(): number

- Returns a number, between 0 and 999999999, representing the nanoseconds.

  #### Returns number

### getTimeT

- getTimeT(): number

- Returns a number representing the seconds since epoch aka time_t.

  JavaScript has the Double precision per default. Instead, Call Timestamp#writeInt64BE to retrieve 64bit long long precision time_t.

  #### Returns number

### getYear

- getYear(): number

- Returns a number representing the year like Date#getUTCFullYear.

  #### Returns number

### toDate

- toDate(): Date

- Returns a Date instance.

  Do not call Date#getUTCFullYear nor Date#getFullYear with the Date instance. Any properties other than those two are correct. Instead, Call Timestamp#getYear to retrieve the year as Timestamp has year offset.

  #### Returns Date

### toJSON

- toJSON(): string

- Returns a JSON string representation like: "2017-11-26T11:27:58.737Z"

  #### Returns string

### toString

- toString(format?: string): string

- Returns a string formatted like strftime does.

  #### Parameters

  - ##### Optional format: string

    "%Y-%m-%dT%H:%M:%S.%NZ", "%a, %b %d %X %Y %z (%Z)", etc.

  #### Returns string

### writeInt64BE

- writeInt64BE(buffer: Uint8Array, offset?: number): Uint8Array
- writeInt64BE(buffer?: number[], offset?: number): number[]

- Writes big endian 64bit time_t of 8 bytes sequence.

  #### Parameters

  - ##### buffer: Uint8Array

    Buffer, Array, Uint8Array, etc.

  - ##### Optional offset: number

  #### Returns Uint8Array

- #### Parameters

  - ##### Optional buffer: number[]

  - ##### Optional offset: number

  #### Returns number[]

### writeInt64LE

- writeInt64LE(buffer: Uint8Array, offset?: number): Uint8Array
- writeInt64LE(buffer?: number[], offset?: number): number[]

- Writes little endian 64bit time_t of 8 bytes sequence.

  #### Parameters

  - ##### buffer: Uint8Array

    Buffer, Array, Uint8Array, etc.

  - ##### Optional offset: number

  #### Returns Uint8Array

- #### Parameters

  - ##### Optional buffer: number[]

  - ##### Optional offset: number

  #### Returns number[]

### Static fromDate

- fromDate(date: Date | number): Timestamp

- Creates a Timestamp instance from Date instance or milliseconds since epoch.

  #### Parameters

  - ##### date: Date | number

    Milliseconds since epoch

  #### Returns Timestamp

### Static fromInt64BE

- fromInt64BE(time: Uint8Array, offset?: number): Timestamp
- fromInt64BE(time: number[], offset?: number): Timestamp

- Creates a Timestamp instance from big endian 64bit time_t of 8 bytes sequence.

  #### Parameters

  - ##### time: Uint8Array

  - ##### Optional offset: number

  #### Returns Timestamp

- #### Parameters

  - ##### time: number[]

  - ##### Optional offset: number

  #### Returns Timestamp

### Static fromInt64LE

- fromInt64LE(time: Uint8Array, offset?: number): Timestamp
- fromInt64LE(time: number[], offset?: number): Timestamp

- Creates a Timestamp instance from little endian 64bit time_t of 8 bytes sequence.

  #### Parameters

  - ##### time: Uint8Array

  - ##### Optional offset: number

  #### Returns Timestamp

- #### Parameters

  - ##### time: number[]

  - ##### Optional offset: number

  #### Returns Timestamp

### Static fromString

- fromString(string: string): Timestamp

- Creates a Timestamp instance from string like: "2017-11-26T11:27:58.737Z"

  see

    https://www.w3.org/TR/NOTE-datetime

  #### Parameters

  - ##### string: string

    W3C Date and Time Formats

  #### Returns Timestamp

### Static fromTimeT

- fromTimeT(time: number): Timestamp

- Creates a Timestamp instance from seconds since epoch aka time_t.

  #### Parameters

  - ##### time: number

    Seconds since epoch

  #### Returns Timestamp

Generated using TypeDoc