|
| 1 | +--- |
| 2 | +description: General information based on the latest ./README.md content |
| 3 | +globs: |
| 4 | +--- |
| 5 | +Update it if APIs change: |
| 6 | + |
| 7 | +# ts-datetime |
| 8 | + |
| 9 | +A modern, immutable, and fully-typed TypeScript datetime library inspired by Carbon (PHP) and Day.js. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- 🔄 **Immutable API** _All operations return new instances_ |
| 14 | +- ⛓️ **Fluent Interface** _Chainable, readable, and expressive_ |
| 15 | +- 🌍 **Locale Support** _Global, per-instance, and per-call configuration_ |
| 16 | +- 📅 **Robust Parsing** _ISO, timestamps, relative strings (e.g. "next week", "+2 days")_ |
| 17 | +- ⏱️ **Intervals & Periods** _Built-in support for durations and date ranges_ |
| 18 | +- 💪 **TypeScript First** _Fully typed, with great DX in modern editors_ |
| 19 | +- ✅ **Tested** _Thoroughly tested for edge cases and correctness_ |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +```bash |
| 24 | +# npm |
| 25 | +npm install @stacksjs/ts-datetime |
| 26 | + |
| 27 | +# pnpm |
| 28 | +pnpm add @stacksjs/ts-datetime |
| 29 | + |
| 30 | +# yarn |
| 31 | +yarn add @stacksjs/ts-datetime |
| 32 | + |
| 33 | +# bun |
| 34 | +bun add @stacksjs/ts-datetime |
| 35 | +``` |
| 36 | + |
| 37 | +## Quick Examples |
| 38 | + |
| 39 | +```ts |
| 40 | +import { Datetime, DatetimeInterval, DatetimePeriod } from 'ts-datetime' |
| 41 | + |
| 42 | +// Creating dates |
| 43 | +const now = Datetime.now() |
| 44 | +const tomorrow = Datetime.tomorrow() |
| 45 | +const specificDate = new Datetime('2024-01-01T12:00:00Z') |
| 46 | + |
| 47 | +// Manipulation |
| 48 | +const nextWeek = now.addDays(7) |
| 49 | +const lastMonth = now.subMonths(1) |
| 50 | + |
| 51 | +// Formatting |
| 52 | +console.log(specificDate.format('YYYY-MM-DD')) // "2024-01-01" |
| 53 | +console.log(now.diffForHumans()) // "just now" |
| 54 | + |
| 55 | +// Intervals |
| 56 | +const interval = DatetimeInterval.days(5).add(DatetimeInterval.hours(12)) |
| 57 | +console.log(interval.forHumans()) // "5 days 12 hours" |
| 58 | + |
| 59 | +// Periods (date ranges) |
| 60 | +const period = new DatetimePeriod( |
| 61 | + new Datetime('2024-01-01'), |
| 62 | + new Datetime('2024-01-10'), |
| 63 | + DatetimeInterval.days(2) |
| 64 | +) |
| 65 | + |
| 66 | +// Iterate over period |
| 67 | +for (const date of period) { |
| 68 | + console.log(date.format('YYYY-MM-DD')) |
| 69 | +} |
| 70 | +// 2024-01-01, 2024-01-03, 2024-01-05, 2024-01-07, 2024-01-09 |
| 71 | +``` |
| 72 | + |
| 73 | +## Documentation |
| 74 | + |
| 75 | +For full documentation, visit [ts-datetime.netlify.app](https://ts-datetime.netlify.app). |
| 76 | + |
| 77 | +- [Introduction](https://ts-datetime.netlify.app/intro) |
| 78 | +- [Installation](https://ts-datetime.netlify.app/install) |
| 79 | +- [Usage](https://ts-datetime.netlify.app/usage) |
| 80 | +- [Configuration](https://ts-datetime.netlify.app/config) |
| 81 | + |
| 82 | +### Feature Documentation |
| 83 | + |
| 84 | +- [Immutable API](https://ts-datetime.netlify.app/features/immutable-api) |
| 85 | +- [Formatting](https://ts-datetime.netlify.app/features/formatting) |
| 86 | +- [Intervals](https://ts-datetime.netlify.app/features/intervals) |
| 87 | +- [Periods](https://ts-datetime.netlify.app/features/periods) |
| 88 | +- [Human Diffs](https://ts-datetime.netlify.app/features/human-diffs) |
| 89 | +- [Relative Strings](https://ts-datetime.netlify.app/features/relative-strings) |
| 90 | + |
| 91 | +### Advanced Topics |
| 92 | + |
| 93 | +- [Localization](https://ts-datetime.netlify.app/advanced/localization) |
| 94 | +- [Type Safety](https://ts-datetime.netlify.app/advanced/type-safety) |
| 95 | +- [Performance](https://ts-datetime.netlify.app/advanced/performance) |
| 96 | +- [Testing](https://ts-datetime.netlify.app/advanced/testing) |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +```bash |
| 101 | +bun test |
| 102 | +``` |
0 commit comments