https://github.com/termehui/date-utils
Date helper and functions (jalaali)
https://github.com/termehui/date-utils
date-utils jalaali jalaali-utils momentjs
Last synced: 4 months ago
JSON representation
Date helper and functions (jalaali)
- Host: GitHub
- URL: https://github.com/termehui/date-utils
- Owner: termehui
- License: isc
- Created: 2023-09-15T16:34:56.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-25T15:00:05.000Z (over 1 year ago)
- Last Synced: 2025-08-08T23:15:05.227Z (10 months ago)
- Topics: date-utils, jalaali, jalaali-utils, momentjs
- Language: TypeScript
- Homepage:
- Size: 282 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Utils
momentjs based date utils.
## Installation
### CDN
This package published as `dateUtils` module in umd.
```html
```
### 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 ثانیه
```