Skip to content

Commit

Permalink
Update docs to include new ChronoTariff.
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Oct 30, 2023
1 parent 961f518 commit 30aa2d5
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A central class in Nifty ToU is [TemporalRangesTariff](./docs/md/nifty-tou.tempo
that defines a set of tariff values with a set of time-based constraints. The implication is that the
tariff values apply only when all the time-based constraints are valid.

The time-based constraints are encoded as [IntRange](docs/md/nifty-tou.intrange.md) objects,
The time-based constraints are encoded as [IntRange](./docs/md/nifty-tou.intrange.md) objects,
that are integer ranges with minimum and maximum values that define the bounds of the constraint.
The supported time-based constraints are:

Expand Down Expand Up @@ -207,6 +207,26 @@ new TariffRate("Morning Fixed", 125, -2);
new TariffRate("Morning Variable", 1, -1);
```

# Chronological tariffs

The [ChronoTariff](./docs/md/nifty-tou.chronotariff.md) class can be used to model a time-based
"fixed" tariff, such as a daily or monthly charge. For example:

```ts
// construct a chronological tariff @ 10/day
const tariff = new ChronoTariff(ChronoTariffUnit.DAYS, 10);

// calculate the tariff cost over a 7 day time range
const cost =
tariff.rate *
tariff.quantity(
new Date("2024-01-01T00:00:00Z"),
new Date("2024-01-08T00:00:00Z"),
true
);
cost === 70; // 7 days @ 10/day
```

# Language support

Nifty ToU supports parsing and formatting text-based range values, in different languages. For
Expand Down
55 changes: 55 additions & 0 deletions dist/nifty-tou.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,61 @@ export declare class ChronoFieldValue {
get rangeValue(): number | null;
}

/**
* A chronologically-based tariff, such as a "daily" charge.
* @public
*/
export declare class ChronoTariff {
#private;
/**
* Constructor.
*
* @param chronoUnit - the chrono unit
* @param rate - the rate per chrono unit
* @param name - an optional description
*/
constructor(chronoUnit: ChronoTariffUnit, rate: number, name?: string);
/** Get the unit. */
get unit(): ChronoTariffUnit;
/** Get the rate. */
get rate(): number;
/** Get the optional name. */
get name(): string | undefined;
/**
* 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:
*
* ```ts
* 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
* ```
*
* @param from - the starting date
* @param to - the ending date (exclusive)
* @param utc - if `true` then use UTC date components, otherwise assume the local time zone
* @returns the count of units between `from` and `to`, including any fractional component
*/
quantity(from: Date, to: Date, utc?: boolean): number;
}

/**
* An enumeration of supported chronological tariff units of the Gregorian calendar.
* @public
*/
export declare enum ChronoTariffUnit {
/** Days */
DAYS = 0,
/** Weeks */
WEEKS = 1,
/** Months */
MONTHS = 2
}

/**
* API for a comparison between similar objects.
* @public
Expand Down
22 changes: 22 additions & 0 deletions docs/md/nifty-tou.chronotariff._constructor_.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md) &gt; [(constructor)](./nifty-tou.chronotariff._constructor_.md)

## ChronoTariff.(constructor)

Constructor.

**Signature:**

```typescript
constructor(chronoUnit: ChronoTariffUnit, rate: number, name?: string);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| chronoUnit | [ChronoTariffUnit](./nifty-tou.chronotariffunit.md) | the chrono unit |
| rate | number | the rate per chrono unit |
| name | string | _(Optional)_ an optional description |

42 changes: 42 additions & 0 deletions docs/md/nifty-tou.chronotariff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md)

## ChronoTariff class

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

**Signature:**

```typescript
export default class ChronoTariff
```

## Constructors

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(chronoUnit, rate, name)](./nifty-tou.chronotariff._constructor_.md) | | Constructor. |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [name](./nifty-tou.chronotariff.name.md) | <code>readonly</code> | string \| undefined | Get the optional name. |
| [rate](./nifty-tou.chronotariff.rate.md) | <code>readonly</code> | number | Get the rate. |
| [unit](./nifty-tou.chronotariff.unit.md) | <code>readonly</code> | [ChronoTariffUnit](./nifty-tou.chronotariffunit.md) | Get the unit. |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [quantity(from, to, utc)](./nifty-tou.chronotariff.quantity.md) | | <p>Calcualte the count of units between two dates.</p><p>The cost of this tariff can be calculated by multiplying the <code>rate</code> by the result of this method, for example:</p>
```ts
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
```
|

13 changes: 13 additions & 0 deletions docs/md/nifty-tou.chronotariff.name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md) &gt; [name](./nifty-tou.chronotariff.name.md)

## ChronoTariff.name property

Get the optional name.

**Signature:**

```typescript
get name(): string | undefined;
```
38 changes: 38 additions & 0 deletions docs/md/nifty-tou.chronotariff.quantity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md) &gt; [quantity](./nifty-tou.chronotariff.quantity.md)

## ChronoTariff.quantity() method

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:

```ts
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
```

**Signature:**

```typescript
quantity(from: Date, to: Date, utc?: boolean): number;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| from | Date | the starting date |
| to | Date | the ending date (exclusive) |
| utc | boolean | _(Optional)_ if <code>true</code> 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

13 changes: 13 additions & 0 deletions docs/md/nifty-tou.chronotariff.rate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md) &gt; [rate](./nifty-tou.chronotariff.rate.md)

## ChronoTariff.rate property

Get the rate.

**Signature:**

```typescript
get rate(): number;
```
13 changes: 13 additions & 0 deletions docs/md/nifty-tou.chronotariff.unit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariff](./nifty-tou.chronotariff.md) &gt; [unit](./nifty-tou.chronotariff.unit.md)

## ChronoTariff.unit property

Get the unit.

**Signature:**

```typescript
get unit(): ChronoTariffUnit;
```
22 changes: 22 additions & 0 deletions docs/md/nifty-tou.chronotariffunit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [nifty-tou](./nifty-tou.md) &gt; [ChronoTariffUnit](./nifty-tou.chronotariffunit.md)

## ChronoTariffUnit enum

An enumeration of supported chronological tariff units of the Gregorian calendar.

**Signature:**

```typescript
export declare enum ChronoTariffUnit
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| DAYS | <code>0</code> | Days |
| MONTHS | <code>2</code> | Months |
| WEEKS | <code>1</code> | Weeks |

2 changes: 2 additions & 0 deletions docs/md/nifty-tou.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A delightful little library for working with time-of-use tariffs.
| --- | --- |
| [ChronoFieldFormatter](./nifty-tou.chronofieldformatter.md) | Class to parse locale-specific chronological field names of the Gregorian calendar. |
| [ChronoFieldValue](./nifty-tou.chronofieldvalue.md) | A chronological field value. |
| [ChronoTariff](./nifty-tou.chronotariff.md) | A chronologically-based tariff, such as a "daily" charge. |
| [IntRange](./nifty-tou.intrange.md) | An immutable number range with min/max values. |
| [NumberFormatter](./nifty-tou.numberformatter.md) | A locale-specific number parser. |
| [TariffRate](./nifty-tou.tariffrate.md) | An identifiable tariff rate. |
Expand All @@ -25,6 +26,7 @@ A delightful little library for working with time-of-use tariffs.
| Enumeration | Description |
| --- | --- |
| [ChronoField](./nifty-tou.chronofield.md) | An enumeration of supported chronological fields of the Gregorian calendar. |
| [ChronoTariffUnit](./nifty-tou.chronotariffunit.md) | An enumeration of supported chronological tariff units of the Gregorian calendar. |

## Interfaces

Expand Down
16 changes: 16 additions & 0 deletions etc/nifty-tou.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ export class ChronoFieldValue {
get value(): number;
}

// @public
export class ChronoTariff {
constructor(chronoUnit: ChronoTariffUnit, rate: number, name?: string);
get name(): string | undefined;
quantity(from: Date, to: Date, utc?: boolean): number;
get rate(): number;
get unit(): ChronoTariffUnit;
}

// @public
export enum ChronoTariffUnit {
DAYS = 0,
MONTHS = 2,
WEEKS = 1
}

// @public
export interface Comparable<T> {
compareTo(o: T | undefined): number;
Expand Down

0 comments on commit 30aa2d5

Please sign in to comment.