Home > nifty-tou > 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.
Signature:
export default class TemporalRangesTariff implements Comparable<TemporalRangesTariff>
Implements: Comparable<TemporalRangesTariff>
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:
Constraint | Bounds | Description |
---|---|---|
monthRange | 1 - 12 | January - December |
dayOfMonthRange | 1 - 31 | |
dayOfWeekRange | 1 - 7 | Monday - Friday |
minuteOfDayRange | 0 - 1440 | 00:00 - 24:00 |
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")]
);
Constructor | Modifiers | Description |
---|---|---|
(constructor)(monthRange, dayOfMonthRange, dayOfWeekRange, minuteOfDayRange, rates) | Constructor. |
Property | Modifiers | Type | Description |
---|---|---|---|
ALL_DAYS_OF_MONTH |
|
IntRange | Range for all days of a month: 1 - 31 (inclusive). |
ALL_DAYS_OF_WEEK |
|
IntRange | Range for all days of a week: 1 - 7 (inclusive). |
ALL_MINUTES_OF_DAY |
|
IntRange | Range for all minutes of a day: 0 - 1440 (inclusive min, exclusive max). |
ALL_MONTHS |
|
IntRange | Range for all months of a year: 1 - 12 (inclusive). |
dayOfMonthRange | readonly |
IntRange | undefined | Get the day of month range. |
dayOfWeekRange | readonly |
IntRange | undefined | Get the day of week range. |
minuteOfDayRange | readonly |
IntRange | undefined | Get the minute of day range. |
monthRange | readonly |
IntRange | undefined | Get the month of year range. |
rates | readonly |
Record<string, TariffRate> | Get the rates, as an object of rate ID to TariffRate objects. |
Method | Modifiers | Description |
---|---|---|
appliesAt(date, utc) | Test if this tariff applies on a given date. All range constraints are treated as inclusive bounds, except for the |
|
compareTo(o) | Compares this object with the specified object for order. Unbounded ( |
|
componentsDescription() | protected |
Get a string representation of the components of this description. |
format(locale, field, options) | Format a field range into a locale-specific string. | |
formatRange(locale, field, value, options) | static |
Format a field range value into a locale-specific string. |
parse(locale, monthRange, dayOfMonthRange, dayOfWeekRange, minuteOfDayRange, rates, options) | static |
Parse time range criteria into a TemporalRangesTariff instance. |
toString() | Get a string representation. |