-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added ru readme file for landing (#85)
- Loading branch information
1 parent
3e1b974
commit 55ceb88
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# @gravity-ui/date-utils | ||
|
||
Утилиты для управления датой и временем. | ||
|
||
## Установка | ||
|
||
```shell | ||
npm i @gravity-ui/date-utils | ||
``` | ||
|
||
## Использование | ||
|
||
```typescript | ||
import {dateTimeParse, dateTime} from '@gravity-ui/date-utils'; | ||
|
||
// Current date: 2021-08-07T12:10:00 | ||
// User's time zone: Europe/Istanbul | ||
|
||
const FORMAT = 'YYYY-MM-DDTHH:mm:ssZ'; | ||
|
||
// parse absolute date | ||
dateTimeParse({year: 2021, month: 7, day: 7})?.format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTimeParse([2021, 7, 7])?.format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTimeParse('2021-08-07')?.format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTimeParse(1621708204063)?.format(FORMAT); // "2021-05-22T21:30:04+03:00" | ||
dateTimeParse('')?.format(FORMAT); // undefined | ||
dateTimeParse('incorrect-date')?.format(FORMAT); // undefined | ||
|
||
// parse relative date | ||
dateTimeParse('now')?.format(FORMAT); // "2021-08-07T12:10:00+03:00" | ||
dateTimeParse('now-1d')?.format(FORMAT); // "2021-08-06T12:10:00+03:00" | ||
dateTimeParse('now-1d+1M')?.format(FORMAT); // "2021-09-06T12:10:00+03:00" | ||
dateTimeParse('now/d')?.format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTimeParse('now+1d/d')?.format(FORMAT); // "2021-08-08T00:00:00+03:00" | ||
dateTimeParse('now-1f')?.format(FORMAT); // undefined | ||
|
||
// create dateTime | ||
dateTime().format(FORMAT); // "2021-08-07T12:10:00+03:00" | ||
dateTime({input: '2021-08-07'}).format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTime({input: '2021-08-07', format: 'YYYY-MM-DD'}).format(FORMAT); // "2021-08-07T00:00:00+03:00" | ||
dateTime({timeZone: 'Asia/Tokyo'}).format(FORMAT); // "2021-08-07T18:10:00+09:00 | ||
dateTime({input: ''}).format(FORMAT); // "Invalid Date" | ||
dateTime({input: '2021-08', format: 'YYYY-MM-DD'}).format(FORMAT); // "Invalid Date" | ||
``` | ||
|
||
## Настройки | ||
|
||
```typescript | ||
import {settings} from '@gravity-ui/date-utils'; | ||
|
||
// Locales management | ||
settings.getLocale(); // default locale "en" | ||
settings.loadLocale('de').then(() => { | ||
settings.setLocale('de'); | ||
settings.getLocale(); // "de" | ||
}); | ||
|
||
// Customization | ||
settings.updateLocale({weekStart: 0}); // change first day of week | ||
``` |