Class HSpan

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 toLuxonInterval and toMomentRange.

Hierarchy

  • HSpan

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, end) => IntervalType;
          };
      }
      • DateTime: any
      • Interval: {
            fromDateTimes(start, end) => IntervalType;
        }
        • fromDateTimes:function
          • Parameters

            • start: any
            • end: any

            Returns IntervalType

    • Optional _now: Date

    Returns IntervalType

    A luxon interval.

    Link

    Luxon

  • Convert the span to a moment range.

    import * as Moment from 'moment-timezone'
    import { extendMoment } from 'moment-range'
    const moment = extendMoment(Moment)
    ...
    const range = new HSpan({ mode: SpanMode.today })
    .toMomentRange(moment)

    Type Parameters

    • MomentType

    Parameters

    • moment: (() => MomentType)
        • (): MomentType
        • Returns MomentType

    • Optional _now: Date

    Returns MomentType

  • 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.

Generated using TypeDoc