# date-slayer

> JS/TS Persian & Gregorian date utils

Latest version **0.0.5** (published 2023-04-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2023-04-16 |
| First published | 2022-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Sina Khodabandehloo |
| Maintainers | sinakhx |
| Keywords | date, utility, date-conversion, jalali, jalaali, gregorian, persian, hijri, shamsi |

## Links

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

## 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

- 0.0.5 (latest) — 2023-04-16
- 0.0.4 — 2023-04-16
- 0.0.3 — 2023-04-16
- 0.0.2 — 2022-10-12

## README

# **date-slayer**
<!-- ![npm](https://img.shields.io/npm/v/date-slayer?color=%23b8860b&style=flat-square) -->
<!-- ![license](https://img.shields.io/npm/l/date-slayer?color=red&style=flat-square) -->
<!-- ![tests](https://img.shields.io/badge/tests-100%25-green?style=flat-square) -->
<!-- ![types](https://img.shields.io/npm/types/date-slayer?style=flat-square) -->


*[This is a work in progress]*

## About
date-slayer is an Intl-API-based native JavaScript solution to common date/time conversion scenarios (mostly around Persian/Jalali Calendar) that are usually handled by various date/time libraries most of which are based on complex solar algorithms & corrections. This one is going to be much more smaller, faster & practical due to skipping implementation details thanks to having EcmaScript's Internationalization API being already implemented by JavaScript runtimes & browsers in hand. So, hopefully this will be a great alternative to all those old solutions based on `date-fns` or `momentjs` or `dayjs`, etc. 

## APIs
### **getJalaliFromGregorian**
converts a Gregorian date into a Jalali object which represents equivalent Jalali date/time details.

```js
import { getJalaliFromGregorian } from 'date-slayer';

const date_2022_04_21 = new Date(1650534589167);
const date = getJalaliFromGregorian(date_2022_04_21);

console.log(date.fa.date)      // -> '۱۴۰۱/۰۲/۰۱'
console.log(date.fa.year)      // -> '۱۴۰۱'
console.log(date.fa.month)     // -> '۰۲'
console.log(date.fa.day)       // -> '۰۱'
console.log(date.fa.weekday)   // -> 'پنجشنبه'
console.log(date.fa.monthLong) // -> 'اردیبهشت'

// all 'fa' methods in this package have equivalent 'en' methods as well
console.log(date.en.date)      // -> '1401/02/01'
console.log(date.en.year)      // -> '1401'
console.log(date.en.month)     // -> '02'
console.log(date.en.day)       // -> '01'
console.log(date.en.weekday)   // -> 'Panjshanbeh'
console.log(date.en.monthLong) // -> 'Ordibehesht'

console.log(date.fa.getDescriptiveDate())               // -> 'پنجشنبه ۱ اردیبهشت'
console.log(date.fa.getDescriptiveDate({ year: true })) // -> 'پنجشنبه ۱ اردیبهشت ۱۴۰۱'

console.log(date.fa.getTime())             // -> '۱۴:۱۹'
console.log(date.fa.getTime('HH:mm'))      // -> '۱۴:۱۹'
console.log(date.fa.getTime('HH:mm:ss'))   // -> '۱۴:۱۹:۴۹'
console.log(date.fa.getTime('hh:mm a'))    // -> '۰۲:۱۹ ب.ظ'
console.log(date.fa.getTime('hh:mm:ss a')) // -> '۰۲:۱۹:۴۹ ب.ظ'
```

____________________________________
### **Want More Examples?**
see the [tests folder][tests-url] for more detailed examples.

____________________________________
### **Contributing**
Please feel free to open an issue or create a pull request to add a new feature or fix a bug. (see [contributing][contribution-url] for more details)

____________________________________

## **License**

The [MIT License][license-url] (MIT)

&copy; 2022 Sina Khodabandehloo

[tests-url]: https://github.com/Sinakhx/date-slayer/tree/main/__tests__/
[contribution-url]:  https://github.com/Sinakhx/date-slayer/blob/main/CONTRIBUTING.md
[changelog-url]:  https://github.com/Sinakhx/date-slayer/blob/main/CHANGELOG.md
[license-url]:  https://github.com/Sinakhx/date-slayer/blob/main/LICENSE

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