# iso8601-interval

> A time duration convert library based on tagged template syntax

Latest version **1.0.2** (published 2022-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install iso8601-interval
pnpm add iso8601-interval
yarn add iso8601-interval
bun add iso8601-interval
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-01-04 |
| First published | 2021-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Crescent Moon |
| Maintainers | t565022817 |

## Links

- npm: https://www.npmjs.com/package/iso8601-interval
- Repository: https://github.com/CrescentSine/iso8601-interval
- Homepage: https://github.com/CrescentSine/iso8601-interval#readme
- Issues: https://github.com/CrescentSine/iso8601-interval/issues
- npm.io page: https://npm.io/package/iso8601-interval

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.1

## Recent versions

- 1.0.2 (latest) — 2022-01-04
- 1.0.1 — 2021-03-08

## README

# iso8601-interval

[![Node.js CI](https://github.com/CrescentSine/iso8601-interval/actions/workflows/node.js.yml/badge.svg)](https://github.com/CrescentSine/iso8601-interval/actions/workflows/node.js.yml)
[![npm](https://img.shields.io/npm/v/iso8601-interval)](https://www.npmjs.com/package/iso8601-interval)
[![GitHub](https://img.shields.io/github/license/CrescentSine/iso8601-interval)](https://github.com/CrescentSine/iso8601-interval/blob/main/LICENSE)
[![npm bundle size](https://img.shields.io/bundlephobia/min/iso8601-interval)](https://www.npmjs.com/package/iso8601-interval)
[![GitHub top language](https://img.shields.io/github/languages/top/CrescentSine/iso8601-interval)](https://www.typescriptlang.org/)
[![Coverage Status](https://coveralls.io/repos/github/CrescentSine/iso8601-interval/badge.svg?branch=main)](https://coveralls.io/github/CrescentSine/iso8601-interval?branch=main)
[![GitHub issues](https://img.shields.io/github/issues/CrescentSine/iso8601-interval)](https://github.com/CrescentSine/iso8601-interval/issues)

A time duration convert library based on tagged template syntax.

## The ISO8601 duration format

Durations in ISO8601 comes in two formats:

* **`PnYnMnDTnHnMnS`**  - `P<date>T<time>`
  The `n` is replaced by the value for each of the date and time elements that follow the `n`.
* **`PnW`** - the week format.

Check out the details on [Wikipedia](https://en.wikipedia.org/wiki/ISO_8601#Durations)

## Install

```bash
npm install iso8601-interval
```

then `import` to your js module

```javascript
import { duration, dur, period, per, interval, invl } from "time-interval";
```

## Usage

* `duration` or `dur`

    Create a Duration Object to represent the number of milliseconds elapsed.

    It is allowed to process data in the format of `PTnHnMnS`, the input number can be decimals, but the number of milliseconds obtained will be rounded to an integer.

    ```javascript
    dur`PT1S`.ms; // => 1000
    dur`PT${1/3}S`.ms; // => 333
    dur`PT1M`.sub(dur`PT1S`).s; // => 59
    dur`PT24H`.toDate(new Date(2021, 0, 1)); // => Date 2020-01-02
    dur`PT10S`.s == duration.ofSeconds(10).s;
    // Make Timer duration param easier to read
    setTimeout(..., dur`PT1S`.ms);
    ```

* `period` or `per`

    Create a Period Object to represent the duration of Date.

    It is allowed to process data in the format of `PnYnMnWnD` (Although this format does not meet the standard), the input number of years and weeks can be decimals, but the number of days and months obtained will be rounded to an integer.

    ```javascript
    per`P1Y3D`.getCertainDays(); // => 3
    per`P1Y3D`.getFullMonths(); // => 12
    per`P1M`.toDuration(new Date(2021, 0, 1)).h; // => 28 * 24
    per`P1M`.toDate(new Date(2021, 0, 1)); // => Date 2020-03-01
    period.ofWeeks(1).getCertainDays(); // => 7
    ```

* `interval` or `invl`

    Create a Object contains a Duration and a Period.

    It is allowed to process full ISO8601 data in the format of `PnYnMnWnDTnHnMnS`, input parameters will be passed to duration and period for processing separately.

    ```javascript
    invl`P3M2DT60S`.duration.min; // => 1
    invl`P3M2DT60S`.period.getCertainDays(); // => 2
    invl`P3M2DT60S`.period.getFullMonths(); // => 3
    ```

---
_Source: https://npm.io/package/iso8601-interval · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
