An open API service indexing awesome lists of open source software.

https://github.com/jack-weilage/chronosis

An extremely lightweight, modern date management library
https://github.com/jack-weilage/chronosis

date datetime javascript typescript

Last synced: 21 days ago
JSON representation

An extremely lightweight, modern date management library

Awesome Lists containing this project

README

          




[![Downloads per month](https://img.shields.io/npm/dm/chronosis?logo=npm&cacheSeconds=60000)](https://www.npmjs.com/package/chronosis)
[![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/chronosis?exports=Chronosis&cacheSeconds=600)](https://bundlephobia.com/package/chronosis)



> [!WARNING]
> Chronosis is currently in **BETA**. Expect frequent breaking changes as the API and codebase matures.

**The fastest and smallest date manipulation library.**

- **Tiny**: Gzips to less than 1 kilobyte, comparable to the size of only [date-fns](https://github.com/date-fns/date-fns)'s `add` function. That's ~3x smaller than [dayjs](https://github.com/iamkun/dayjs) and ~22x smaller than [luxon](https://github.com/moment/luxon)!
- **Simple**: Only includes necessary functions for manipulation and formatting, excluding excess like equality comparisons.
- **Absurdly fast**: Significantly faster at nearly every single common action than any other similar package.
- **I18N**: Implements [`Intl.DateTimeFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) to translate language-specific terms via the browser.


## Installation

To install, use your preferred package manager to download `chronosis`.

```bash
npm install chronosis
```

For contributors

`chronosis` is developed on Linux, using [bun.sh](https://github.com/oven-sh/bun) as package manager, script runner, bundler, and test runner. Certain parts of the project _may_ work on Windows, but it is highly suggested to [install WSL](https://learn.microsoft.com/en-us/windows/wsl/install) and continue from there.

Once complete, just import the `Chronosis` class into your code, and start programming!

## Usage

Manipulating dates and times should be simple, so `Chronosis` makes it easy.

```ts
import { Chronosis } from 'chronosis'

const now = new Chronosis()

// Familiar, chainable syntax
const noon_tomorrow = now.add(1, 'day').set('hour', 11).startOf('hour')

// Intuitive, internationalized formatting
console.log(noon_tomorrow.format('dddd, MMMM D, YYYY', 'es-MX'))
// Logs something like 'sábado, septiembre 9, 2023'
```

For more detailed information and documentation, see [chronosis.js.org](https://chronosis.js.org).

## Examples

### Find how many days are left in the month

```ts
const now = new Chronosis()
const end_of_month = now.endOf('month')

const days_left = end_of_month.get('day') - now.get('day')
```

## Contributing

Please see [CONTRIBUTING.md](./CONTRIBUTING.md) to see how best to contribute to this project.