# @termehui/date-utils

> Date helper and functions (jalaali)

Latest version **1.0.10** (published 2024-12-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @termehui/date-utils
pnpm add @termehui/date-utils
yarn add @termehui/date-utils
bun add @termehui/date-utils
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2024-12-25 |
| First published | 2023-09-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mekramy |
| Keywords | date, utility, helper, momentjs, jalaali |

## Links

- npm: https://www.npmjs.com/package/@termehui/date-utils
- Repository: https://github.com/termehui/date-utils
- Homepage: https://github.com/termehui/date-utils#readme
- Issues: https://github.com/termehui/date-utils/issues
- npm.io page: https://npm.io/package/@termehui/date-utils

## Dependencies (3)

- [moment](https://npm.io/package/moment.md) ^2.30.1
- [moment-jalaali](https://npm.io/package/moment-jalaali.md) ^0.10.4
- [@types/moment-jalaali](https://npm.io/package/@types/moment-jalaali.md) ^0.7.9

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2024-12-25
- 1.0.9 — 2024-12-25
- 1.0.8 — 2024-12-25
- 1.0.7 — 2024-12-25
- 1.0.6 — 2023-09-16
- 1.0.5 — 2023-09-16
- 1.0.4 — 2023-09-16
- 1.0.3 — 2023-09-16
- 1.0.2 — 2023-09-15
- 1.0.1 — 2023-09-15
- 1.0.0 — 2023-09-15

## README

# Utils

momentjs based date utils.

## Installation

### CDN

This package published as `dateUtils` module in umd.

```html
<script src="https://unpkg.com/@termehui/date-utils"></script>
```

### NPM

```bash
npm i @termehui/date-utils
```

## Usage

### Parse

Parse standard unformatted gregorian date string.

```ts
// Signature
function parse(date: any): Moment;
```

### parseRFC3339

Parse standard date from RFC3339 (`YYYY-MM-DDTHH:mm:ssZ`) format.

```ts
// Signature
function parseRFC3339(date: any): Moment;
```

### parseRFC3339Nano

Parse standard date from RFC3339Nano (`YYYY-MM-DDTHH:mm:ss.SSSSSSSSSZ`) format.

```ts
// Signature
function parseRFC3339Nano(date: any): Moment;
```

### ParseFrom

Parse formatted date from string. For parse jalali date use format params with **j** prefix (see [moment-jalaali](https://github.com/jalaali/moment-jalaali)).

```ts
// Signature
function parseFrom(date: string, format: string): Moment;

// Example
import { parseFrom } from "@termehui/date-utils";
const gregorian = parseFrom("2020-01-12 15", "YYYY-MM-DD HH");
const jalaali = parseFrom("1400-03-19 21", "jYYYY-jMM-jDD HH");
```

### Ago

Get ago string for date.

```ts
// Signature
function ago(date: Moment, locale: "fa" | "en"): string;

// Example
import { parse, ago } from "@termehui/date-utils";

const dt = parse("2020-12-03");
console.log(ago(dt, "en")); // 2 days ago
console.log(ago(dt, "fa")); // 2 روز قبل
```

### Humanize

Get humanized duration string.

```ts
// Signature
function humanize(
  d: number,
  unit: DurationInputArg2 = "ms",
  locale: "fa" | "en" = "fa"
): string;

// Example
import { humanize } from "@termehui/date-utils";
const ts = 1555638000;
console.log(humanize(ts, "ms", "en")); // 21 days, 7 minutes, 18 seconds
console.log(humanize(ts, "ms", "fa")); // 21 روز و 7 دقیقه و 18 ثانیه
```

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