Class HDateTime

Haystack date time.

Hierarchy

  • HDateTime

Implements

Accessors

Methods

  • Compares two date times.

    Parameters

    • value: unknown

      The value value to compare against.

    Returns number

    The sort order as negative, 0, or positive

  • Value equality check.

    Parameters

    • value: unknown

      The value to test.

    Returns boolean

    True if the value is the same.

  • Return the full IANA timezone name or an empty string if it can't be found.

    Parameters

    • isValidTimeZone: ((timezone) => boolean) = defaultIsValidTimeZone

      An optional callback invoked to see if the timezone is valid.

        • (timezone): boolean
        • Parameters

          • timezone: string

          Returns boolean

    Returns string

    The IANA timezone name or an empty string if the timezone name isn't valid.

  • Compares the value's kind.

    Parameters

    • kind: Kind

      The kind to compare against.

    Returns boolean

    True if the kind matches.

  • Returns true if the haystack filter matches the value.

    Parameters

    • filter: string | Node

      The filter to test.

    • Optional cx: Partial<EvalContext>

      Optional haystack filter evaluation context.

    Returns boolean

    True if the filter matches ok.

  • Encodes to an encoded zinc value that can be used in a haystack filter string.

    A dict isn't supported in filter so throw an error.

    Returns string

    The encoded value that can be used in a haystack filter.

  • Return the full IANA timezone name or an empty string if it can't be found.

    The timezone name can be a full existing timezone or an alias.

    Since a vanilla JavaScript environment doesn't have support for querying the IANA database, a callback function needs to be passed in to query the local database implementation.

    Here's an example that uses Luxon...

    import { DateTime } from 'luxon'
    ...
    const isValidTimeZone = (timezone: string): boolean =>
    !!DateTime.now().setZone(timezone).isValid

    const tz = getIANATimeZone('New_York', isValidTimeZone) // Returns 'America/New_York'.
    ...

    Here's an example that uses Moment with timezones...

    import * as moment from 'moment-timezone'
    ...
    const isValidTimeZone = (timezone: string): boolean =>
    !!moment.tz.zone(timezone)

    const tz = getIANATimeZone('New_York', isValidTimeZone) // Returns 'America/New_York'.

    Parameters

    • timezone: string

      A full timezone name or alias.

    • isValidTimeZone: ((timezone) => boolean) = defaultIsValidTimeZone

      An optional callback invoked to see if the timezone is valid.

        • (timezone): boolean
        • Parameters

          • timezone: string

          Returns boolean

    Returns string

    The IANA timezone name or an empty string if the timezone name isn't valid.

Generated using TypeDoc