Skip to content
Myr

README.md

This file

Path

README.md

114 lines · 5.6 KiB · Markdown

Last changed by

landed by oscar94eb6b7

History of this file

Take it

landed by oscabriel6a2b761

lines 1–98
1# datekit
23Small, dependency-free date helpers for TypeScript. datekit reads ISO 8601 text, shows dates with patterns, and adds and diffs in whole units. Dates are plain `Date` instants, and datekit works in UTC unless you name a time zone, so the same code gives the same answer on every machine.45> datekit and its maintainers are fictional: it is an example project made up to show Myr, the git platform it is hosted on.67## Install89```sh10bun add datekit11```1213datekit has no dependencies and ships its TypeScript source, which Bun, Deno and any bundler read as is. It needs a runtime with `Intl` time zone data for the `timeZone` option; Bun, Deno, Node and every current browser have it.1415## Usage1617```ts18import { addMonths, diffInDays, format, parseISO } from "datekit";1920const shipped = parseISO("2026-10-07T14:30:00+01:00");2122format(shipped, "EEE, d MMMM yyyy 'at' HH:mm"); // "Wed, 7 October 2026 at 13:30"23format(shipped, "h:mm a XXX", { timeZone: "Asia/Tokyo" }); // "10:30 PM +09:00"2425const renewal = addMonths(shipped, 3);26format(renewal, "yyyy-MM-dd"); // "2027-01-07"27diffInDays(renewal, shipped); // 9228```2930## Reading dates3132`parseISO(text)` reads ISO 8601:3334- a calendar date: `2026-10-07`, or `20261007`; `2026-10` is the month's first day and `2026` is January 1;35- an ordinal date: `2026-280` is the 280th day of 2026;36- then optionally `T` and a time, `14:30`, `14:30:15` or `14:30:15.250`, with a UTC offset, `Z`, `+09:00` or `-0330`.3738Text with no offset is read as UTC. Digits past the millisecond are dropped, not rounded.3940`parseISO` never throws. Text it can't read, or a day that doesn't exist (`2026-02-29`, `2026-04-31`), gives an invalid date; check with `isValid(date)`.4142## Showing dates4344`format(date, pattern, options?)` shows a date with a pattern, in UTC or in `options.timeZone`.4546| Token | Shows | Example |47| --- | --- | --- |48| `yyyy`, `yy` | year | `2026`, `26` |49| `MMMM`, `MMM`, `MM`, `M` | month | `October`, `Oct`, `10`, `10` |50| `Do`, `dd`, `d` | day of the month | `7th`, `07`, `7` |51| `EEEE`, `EEE` | day of the week | `Wednesday`, `Wed` |52| `HH`, `H` | hour, 24-hour clock | `14`, `14` |53| `hh`, `h`, `a` | hour, 12-hour clock, and AM or PM | `02`, `2`, `PM` |54| `mm`, `ss`, `SSS` | minute, second, millisecond | `05`, `09`, `250` |55| `XXX` | UTC offset | `Z`, `+09:00`, `-04:00` |5657### Format patterns5859- Text in single quotes is printed exactly as written: `'Week of' MMMM d` is `Week of October 7`. Two single quotes print one: `h 'o''clock'` is `2 o'clock`.60- Punctuation, digits and spaces pass through as they are.61- A letter outside quotes that is no token throws a `RangeError`, so a typo never prints a wrong date. So does an invalid date, or a time zone the runtime doesn't know.6263## Moving dates6465`addMilliseconds`, `addSeconds`, `addMinutes`, `addHours`, `addDays`, `addWeeks`, `addMonths` and `addYears` each return a new date and leave their argument alone. Amounts are whole numbers; a fraction is dropped toward zero. Every day in UTC is 24 hours long, so `addDays` adds exact days. `addMonths` keeps the day of the month and the time of day, and `addYears` adds twelve months.6667## Comparing dates6869The `diffIn…` functions take the later date first and count whole units, dropping a part unit toward zero, so the result is negative when the first date is the earlier one.7071| Function | Counts |72| --- | --- |73| `diffInMilliseconds`, `diffInSeconds`, `diffInMinutes`, `diffInHours` | exact time |74| `diffInDays`, `diffInWeeks` | whole 24-hour days and weeks |75| `diffInCalendarDays` | UTC midnights crossed |76| `diffInCalendarMonths` | month boundaries crossed |7778`isLeapYear(year)`, `daysInMonth(year, month)` (months 1 to 12) and `daysInYear(year)` answer calendar questions.7980## Time zones8182datekit keeps instants and never shifts them; a time zone only changes how a date is shown. `format` takes any IANA zone (`Europe/Lisbon`, `America/New_York`) and follows its daylight saving time. `zonedParts(date, timeZone)` gives the wall-clock fields and the offset, `offsetIn(date, timeZone)` the offset alone in minutes east of UTC, and `isTimeZone(name)` says whether the runtime knows a zone. The zone data is the runtime's own, so datekit ships none.8384## Contributing8586What we want changed is written down as asks, one file each in `.myr/asks/`: a sentence saying what should happen, and a test in `test/asks/` that fails until it does. To answer one:8788```sh89myr asks --project datekit # what is open90myr ask format-ordinal # read one in full91myr claim format-ordinal # take it; this prints your fork's remote92git remote add myr <remote> # the remote the claim printed93myr check # run its test and the suite, as the platform will94git push myr HEAD:main # offer your answer95```9697The platform runs the ask's test and the rest of the suite on your answer, and lands it on main with your name on it when both pass. An answer changes only the files its ask names. `format-ordinal` is kept for newcomers, with okonkwo as mentor.98

landed by oscar94eb6b7

line 99why, one step back
99Claiming needs a vouch: a line in `.myr/vouched.td`. Anyone not denounced there may ask for one in a discussion with `myr discussion post`, and a maintainer opens the ask from it.

landed by oscabriel6a2b761

lines 100–114
100
101Run the tests with `bun test`. On main, the three asks' tests fail; everything else passes.102103## Environment104105`.env.schema` declares the variables the docs site and the release step read, in varlock's `@env-spec` format. Test values are committed in `.env.test`. The source-map upload token is set by a maintainer for releases and never committed, and no check ever sees it.106107## Maintainers108109- `ines-v` decides for the whole library.110- `okonkwo` decides for time zones (`src/tz.ts`).111112## License113114MIT