Models a range of time using an inclusive starting timestamp and exclusive ending timestamp.

Please note, due to the lack of date time support in vanilla JavaScript, this implementation relies on using a third party library with proper timezone and locale support. See HSpan.toLuxonInterval and HSpan.toMomentRange.

Constructors

Properties

Exclusive ending time.

mode?: SpanMode

The relative mode. If undefined the span is absolute.

start?: HDate | HDateTime

Inclusive starting time.

timezone: string

The timezone to use.

Methods

  • Convert the span to a Luxon interval.

    The haystack-core has zero runtime dependencies and supports web, node and deno environments. However vanilla JavaScript lacks support for various calendar functions required to make HSpan useful.

    Warning: at the time of writing, the first day of the week does not vary between locales with Luxon.

    import { DateTime, Interval } from 'luxon'

    ...
    const interval = new HSpan({ mode: SpanMode.today })
    .toLuxonInterval({ DateTime, Interval })

    Type Parameters

    • IntervalType

    Parameters

    • __namedParameters: {
          DateTime: any;
          Interval: { fromDateTimes(start: any, end: any): IntervalType };
      }
    • Optional_now: Date

    Returns IntervalType

    A luxon interval.

  • Create a span from a encoded string or undefined if it can't be decoded.

    Decode from string format:

    • relative SpanMode mode name
    • absolute single date: 'YYYY-MM-DD'
    • absolute date span: 'YYYY-MM-DD,YYYY-MM-DD'
    • absolute date time span: 'YYYY-MM-DDThh:mm:ss.FFF zzzz,YYYY-MM-DDThh:mm:ss.FFF zzzz'

    Parameters

    • str: string

      The string to decode.

    Returns undefined | HSpan

    The decoded span or undefined.