Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 5.44 KB

nifty-tou.temporalrangestariff.md

File metadata and controls

83 lines (62 loc) · 5.44 KB

Home > nifty-tou > TemporalRangesTariff

TemporalRangesTariff class

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>

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")]
);

Constructors

Constructor Modifiers Description
(constructor)(monthRange, dayOfMonthRange, dayOfWeekRange, minuteOfDayRange, rates) Constructor.

Properties

Property Modifiers Type Description
ALL_DAYS_OF_MONTH

static

readonly

IntRange Range for all days of a month: 1 - 31 (inclusive).
ALL_DAYS_OF_WEEK

static

readonly

IntRange Range for all days of a week: 1 - 7 (inclusive).
ALL_MINUTES_OF_DAY

static

readonly

IntRange Range for all minutes of a day: 0 - 1440 (inclusive min, exclusive max).
ALL_MONTHS

static

readonly

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.

Methods

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 minuteOfDayRange that is treated as an inclusive minimum and exclusive maximum.

compareTo(o)

Compares this object with the specified object for order.

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

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.