https://github.com/sinclairnick/dateformat-ts
A type-level implementation of date.format()
https://github.com/sinclairnick/dateformat-ts
Last synced: about 1 year ago
JSON representation
A type-level implementation of date.format()
- Host: GitHub
- URL: https://github.com/sinclairnick/dateformat-ts
- Owner: sinclairnick
- Created: 2024-06-10T06:46:44.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T06:53:47.000Z (about 2 years ago)
- Last Synced: 2025-02-10T14:52:51.874Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DateFormat TS
**Format date information at the type-level, according to the [Unicode #35 standard](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)**
---
```ts
// Init date
type Date = FromIso<"2024-06-10T04:39:46.229Z">;
// Format date
type Formatted = Format;
// ^? 10-06-24 4:39:46 AM
```
> This is just a toy project, it's probably not super useful in production
## Usage
Given a `DateObject`
```ts
export type DateObject = {
dayOfMonth: number;
dayOfYear: number;
dayOfWeek: number;
monthOfYear: number;
hourOfDay: number;
minuteOfHour: number;
secondOfMinute: number;
year: number;
};
```
We can format the date information given a format string.
```ts
type FormattedDate = Format;
```
## Limitations
- Not all format parts implemented, like ISO and locale-stuff
- No input validation is done
- Escaping syntax is not respected (not implemented yet)
- `FromIso` does _not_ produce `dayOfYear` or `dayOfWeek` information