# date-extensions

> JavaScript DateExtended.

Latest version **3.0.2** (published 2021-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install date-extensions
pnpm add date-extensions
yarn add date-extensions
bun add date-extensions
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2021-03-31 |
| First published | 2018-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 913.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mateusz Rohde |
| Maintainers | rodziu |

## Links

- npm: https://www.npmjs.com/package/date-extensions
- Repository: https://github.com/Rodziu/date-extensions
- Homepage: https://mateuszrohde.pl/repository/date-extensions
- npm.io page: https://npm.io/package/date-extensions

## Recent versions

- 3.0.2 (latest) — 2021-03-31
- 3.0.1 — 2021-03-31
- 3.0.0 — 2021-02-08
- 2.1.1 — 2021-02-01
- 2.1.0 — 2020-09-16
- 2.0.2 — 2019-08-27
- 2.0.1 — 2019-07-18
- 2.0.0 — 2019-07-16
- 1.1.0 — 2018-10-02
- 1.0.0 — 2018-09-27

## README

# JavaScript DateExtended Extensions

JavaScript Date class extensions that allows one to easily interact with Dates.

## Prerequisites

None :).

## Installation

```
yarn add date-extensions
yarn install
```

## Features

### Localized day and month names

Default locale is en-us.

```javascript
date = new DateExtended('2018-09-01');
date.getDayName(); // Saturday
date.getDayShortName(); // Sat
date.getMonthName(); // September
date.getMonthShortName(); // Sep
```

You can add other locales by including selected locale file from `dist/i18n/*.js`. Locale can be changed at runtime using `DateExtended.setDefaultLocale` or `(DateExtendedInstance).setLocale` functions.

```javascript
date = new DateExtended('2018-09-01');
date.getDayName(); // Saturday
date.setLocale('pl');
date.getDayName(); // Sobota
```

### DateExtended.add & DateExtended.sub

Supported interval types are: `day week month year hour minute second`

```javascript
date = new DateExtended('2018-09-01');
date.add(1, 'year'); // Sun Sep 01 2019 02:00:00 GMT+0200 (CEST)
date.sub(1, 'week'); // Sat Aug 25 2018 02:00:00 GMT+0200 (CEST)
```

### DateExtended.format

Allows one to easily format date object into a string in [PHP way](http://php.net/manual/en/function.date.php).

```javascript
date = new DateExtended('2018-09-01');
date.format('Y-m-d H:i:s l F'); // 2018-09-01 02:00:00, Sobota Wrzesień
```

### DateExtended.clone

Clones date object into new one.

```javascript
date = new DateExtended('2018-09-01');
date.clone().add(1, 'month'); // Mon Oct 01 2018 02:00:00 GMT+0200 (CEST)
// date is still Sat Sep 01 2018 02:00:00 GMT+0200 (CEST)
```

### DateExtended.isValid

Checks if DateExtended object is valid

```javascript
(new DateExtended('2018-09-01')).isValid(); // true
(new DateExtended('0000-00-00')).isValid(); // false
```

### DateExtended.createFromFormat

Parses a date string according to a specified format.
Supported format tokens are: d, j, F, M, m, n, Y, y, G, g, H, h, i, s. Any other characters are being ignored.
Token meanings are the same as in [PHP language](http://php.net/manual/en/datetime.createfromformat.php).

```javascript
DateExtended.createFromFormat('H:i:s j F Y', '12:59:03 4 Listopad 2017'); // Sat Nov 04 2017 12:59:03 GMT+0100 (CET)
```

### DateExtended.createFromDate

You can create DateExtended instance from Date instance.

```javascript
DateExtended.createFromDate(new Date);
```

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