Class ChronoTariff

A chronologically-based tariff, such as a "daily" charge.

Hierarchy

  • ChronoTariff

Constructors

Properties

#name?: string

An optional name to associate with the tariff.

#rate: number

The rate applied per time unit.

The tariff time unit.

Accessors

  • get name(): undefined | string
  • Get the optional name.

    Returns undefined | string

Methods

  • Parameters

    • from: Date
    • to: Date
    • Optional utc: boolean

    Returns number

  • Parameters

    • from: Date
    • to: Date
    • Optional utc: boolean

    Returns number

  • Parameters

    • from: Date
    • to: Date
    • Optional refFrom: Date
    • Optional refTo: Date

    Returns number

  • Parameters

    • from: Date
    • to: Date
    • Optional utc: boolean

    Returns number

  • Calcualte the count of units between two dates.

    The cost of this tariff can be calculated by multiplying the rate by the result of this method, for example:

    const tariff = new ChronoTariff(ChronoTariffUnit.DAYS, 10);
    tariff.rate * tariff.quantity(
    new Date('2024-01-01T00:00:00Z'),
    new Date('2024-01-08T00:00:00Z'),
    true) === 70; // 7 days @ 10/day

    Parameters

    • from: Date

      the starting date

    • to: Date

      the ending date (exclusive)

    • Optional utc: boolean

      if true then use UTC date components, otherwise assume the local time zone

    Returns number

    the count of units between from and to, including any fractional component

Generated using TypeDoc