Class TemporalRangesTariff

A tariff with time-based range rules.

The rules associated with this tariff are represented by a set of date ranges that serve as the constraints that must be satisfied by a given date for the rule to apply.

Remarks

The date range constraints use inclusive minimum/maximum matching semantics, except for the minuteOfDayRange constraint, that uses inclusive minimum and exclusive maximum semantics.

The time-based constraints supported are:

ConstraintBoundsDescription
monthRange1 - 12January - December
dayOfMonthRange1 - 31
dayOfWeekRange1 - 7Monday - Friday
minuteOfDayRange0 - 144000:00 - 24:00

Example

The parse() method provides an easy way to parse instances from language-specific time range values:

// a tariff for weekday mornings
const tt = TemporalRangesTariff.parse(
"en-US",
"*",
"*",
"Mon - Fri",
"0 - 12",
[new TariffRate("Weekday AM", "1.23")]
);

// a tariff for weekday evenings
const tt = TemporalRangesTariff.parse(
"en-US",
"*",
"*",
"Mon - Fri",
"12 - 24",
[new TariffRate("Weekday PM", "2.34")]
);

Hierarchy

Implements

Constructors

  • Constructor.

    Parameters

    • Optional monthRange: IntRange

      the month range (1-12, inclusive)

    • Optional dayOfMonthRange: IntRange

      the day of month range (1-31, inclusive)

    • Optional dayOfWeekRange: IntRange

      the day of week range (1-7, with 1 = Monday, 7 = Sunday, inclusive)

    • Optional minuteOfDayRange: IntRange

      the minute of day range (0-1440, inclusive minimum, exclusive maximum)

    • Optional rates: TariffRate[]

      the rates, as an array of TariffRate objects

    Returns TemporalRangesTariff

Properties

#dayOfMonthRange?: IntRange
#dayOfWeekRange?: IntRange
#minuteOfDayRange?: IntRange
#monthRange?: IntRange
#rates: Record<string, TariffRate>

Accessors

Methods

  • Translate a Date day value into a range between 1..7.

    Parameters

    • value: number

      the Date day value to translate

    Returns number

    the day-of-week value with Monday == 1, Sunday == 7

  • Translate a Date month value into a range between 1..12.

    Parameters

    • value: number

      the Date month value to translate

    Returns number

    the month value with January == 1, December == 12

  • Test if an optional range contains a value.

    Parameters

    • value: number

      the number to test if the range contains

    • Optional range: IntRange

      the range to test

    • Optional exclusiveEnd: boolean

      if true then treat the range end as an exclusive bound

    Returns boolean

    true if the given range is not defined, or it contains the given value

  • Test if this tariff applies on a given date.

    All range constraints are treated as inclusive bounds, except for the minuteOfDayRange that is treated as an inclusive minimum and exclusive maximum.

    Parameters

    • date: Date

      the date to test if this rate applies at

    • Optional utc: boolean

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

    Returns boolean

    true if this tariff applies on the given date

  • Compares this object with the specified object for order.

    Unbounded (null) values are ordered before bounded (non-null) values.

    Parameters

    Returns number

    -1, 0, or 1 if this is less than, equal to, or greater than o

  • Get a string representation of the components of this description.

    Returns string

    string representation of the components of this tariff

    Remarks

    The toString() method will call this to generate a string representation of this tariff. Extending classes can override this method (possibly invoking this implementation to pick up the components rendered by this class).

  • Format a field range into a locale-specific string.

    Parameters

    Returns string

    the formatted field range value

    Throws

    TypeError if field is not supported

  • Format a field range value into a locale-specific string.

    Parameters

    Returns string

    the formatted field range value

    Throws

    TypeError if field is not supported

  • Parse time range criteria into a TemporalRangesTariff instance.

    Parameters

    • locale: string

      the locale to parse the ranges as

    • Optional monthRange: string

      the month range to parse, for example January-December, Jan-Dec, or 1-12

    • Optional dayOfMonthRange: string

      the day of month range to parse, for example 1-31

    • Optional dayOfWeekRange: string

      the day of week range to parse, for example Monday-Sunday, Mon-Sun, or 1-7

    • Optional minuteOfDayRange: string

      the minute of day range to parse, for example 00:00-24:00 or 0-24

    • Optional rates: TariffRate[]

      the tariff rates to associate with the time range criteria

    • Optional options: TemporalRangesTariffFormatOptions

      the formatting options to use

    Returns TemporalRangesTariff

    the new instance

    Remarks

    Note that the minuteOfDayRange can be specified as a range of HH:MM 24-hour hour and minute values, or whole hours. For example 01:00-08:00 and 1-8 are equivalent.

    Additionally, all range values may be specified as * to mean "all possible values", in which that range will be resolved to undefined.

Generated using TypeDoc