Options
All
  • Public
  • Public/Protected
  • All
Menu

This class provides the additional semantics necessary for Ion timestamp values.

Hierarchy

  • Timestamp

Index

Constructors

constructor

  • new Timestamp(date: Date): Timestamp
  • new Timestamp(localOffset: number, year: number, month?: null | number, day?: null | number, hour?: null | number, minutes?: null | number, seconds?: null | number | Decimal): Timestamp
  • Creates a new Ion Timestamp with millisecond precision from a JavaScript Date.

    Parameters

    • date: Date

      a valid JavaScript date object

    Returns Timestamp

  • Creates a new Timestamp, with precision determined by which parameters are provided. If a parameter is not specified, it defaults to its lowest valid value; defaulted values are not used when determining the precision.

    Logically, an instance of this class represents an instant in time based on an offset from UTC and the other provided parameters.

    Parameters

    • localOffset: number

      Local offset from UTC (range: [-(23*60+59):(23*60+59)])

    • year: number

      the year (range: [1-9999])

    • Optional month: null | number

      the month (range: [1-12])

    • Optional day: null | number

      the day of the month (range: [1-31])

    • Optional hour: null | number

      the hour of the day (range: [0-23])

    • Optional minutes: null | number

      number of minutes (range: [0-59])

    • Optional seconds: null | number | Decimal

      number of seconds specified as a number (range: [0-59]), or a Decimal (range: [0.0-60.0)) in order to express whole seconds along with some fractional seconds

    Returns Timestamp

Methods

compareTo

  • Compares this Timestamp with another and returns -1, 0, or 1 if the instant represented by this Timestamp occurs before, at the same time, or after the other Timestamp.

    Note that a return value of 0 from this method doesn't guarantee that equals() will return true, as compareTo() doesn't require the values to have the same precision and local offset to be considered the same instant, whereas equals() does. The following table illustrates this behavior:

    Timestamp 1 Timestamp 2 compareTo equals
    2001T 2001T 0 true
    2001-01-01T 2001-01-01T 0 true
    2001-01-01T00:00:00.000Z 2001-01-01T00:00:00.000Z 0 true
    2001T 2001-01-01T 0 false
    2001T 2001-01-01T00:00:00.000Z 0 false
    2001-01-01T00:00Z 2000-12-31T23:59-00:01 0 false

    Parameters

    Returns number

equals

  • Compares this Timestamp with another and returns true if they represent the same instant and have the same precision. Note that this differs from compareTo(), which doesn't require precision to match when returning 0.

    Parameters

    Returns boolean

getDate

  • getDate(): Date
  • Returns a Date representing the value of this Timestamp. Note that this may be a lossy operation, as a Date cannot fully represent all Timestamp values. Specifically:

    • fractional seconds of a Timestamp beyond millisecond precision are rounded to the nearest millisecond in the returned Date
    • if the precision of this Timestamp is YEAR or MONTH, the returned Date's month and day are set to January 1
    • the returned Date object is not aware of this Timestamp's local offset property

    With the exception of the discrepancies noted above, the returned Date will represent the same instant in time as this Timestamp. However, most methods of the Date API will return properties in the local date and time of the instant, which may differ from the local offset of the Timestamp. The Date class also provides methods for retrieving the properties of the instant in UTC.

    Returns Date

getLocalOffset

  • getLocalOffset(): number

getPrecision

getSecondsDecimal

getSecondsInt

  • getSecondsInt(): number
  • Returns the number of seconds as an integer value; any fractional seconds are truncated.

    Returns number

toJSON

  • toJSON(): string
  • Converts this Timestamp to a ISO8601-formatted string when being serialized with JSON.stringify().

    Returns string

toString

  • toString(): string

Static parse