Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.52 KB

nifty-tou.chronotariff.md

File metadata and controls

42 lines (30 loc) · 1.52 KB

Home > nifty-tou > ChronoTariff

ChronoTariff class

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

Signature:

export default class ChronoTariff 

Constructors

Constructor Modifiers Description
(constructor)(chronoUnit, rate, name) Constructor.

Properties

Property Modifiers Type Description
name readonly string | undefined Get the optional name.
rate readonly number Get the rate.
unit readonly ChronoTariffUnit Get the unit.

Methods

Method Modifiers Description
quantity(from, to, utc)

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

|