⚠️ Major Breaking Changes in v1.0.0+
- The user-facing API of Datify has been completely rewritten.
- Functions like
day-name,month-name, etc. are no longer available directly in Datify. They have been moved to datify-core, which Datify uses as its backend. Example migration:#import "@preview/datify-core:1.0.0": * #get-day-name(datetime.today().weekday(), lang: "en") // Now available in datify-core- The new backend is based on the Unicode CLDR project, providing robust internationalization.
- If you need to resolve a single day or month name, it is recommended to use
datify-coredirectly. You can also usecustom-date-formatfor this, but it is less practical for single values.- The core logic for string transformation now uses a formal language and automata approach, similar to many modern date libraries. This introduces a new quoting system for escaping text in patterns.
- If you are migrating from a previous version, your code will need to be updated. The old usage is not compatible with this version.
- Overview
- Installation
- Usage
- Supported Languages
- Contributing
- License
- Development & Testing
- Planned Features
- Glossary
Datify is a Typst package for flexible, locale-aware date formatting. It leverages datify-core for internationalization and supports CLDR-style date patterns.
Add Datify to your Typst project (specify the version you want):
#import "@preview/datify:1.0.1": *| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| date | datetime | Yes | – | The date to format |
| pattern | str | No | "full" | Pattern string or CLDR named pattern |
| lang | str | No | "en" | ISO 639-1 language code (e.g., "en", "fr", "es") |
If you only provide lang, the pattern defaults to "full" for that
locale. All arguments must be named except for the first (date).
#let mydate = datetime(year: 2025, month: 1, day: 5)
#custom-date-format(mydate) // Output: Sunday, January 5, 2025 (in English, full format)
#custom-date-format(mydate, lang: "es") // Output: domingo, 5 de enero de 2025
#custom-date-format(mydate, pattern: "yyyy-MM-dd") // Output: 2025-01-05
#custom-date-format(mydate, pattern: "full", lang: "fr") // Output: dimanche 5 janvier 2025The pattern argument can be either:
- A CLDR named pattern (
"full","long","medium","short") for locale-appropriate formatting. - A custom string pattern using the tokens below.
#custom-date-format(mydate, pattern: "full", lang: "fr") // Output: dimanche 5 janvier 2025#custom-date-format(mydate, pattern: "EEEE, MMMM dd, yyyy") // Output: Sunday, January 05, 2025
#custom-date-format(mydate, pattern: "EEE, MMM d, yyyy") // Output: Sun, Jan 5, 2025| Token | Description | Example Output |
|---|---|---|
EEEE |
Full weekday name | Sunday |
EEE |
Abbreviated weekday name | Sun |
MMMM |
Full month name | January |
MMM |
Abbreviated month name | Jan |
MM |
Month number, 2 digits | 01 |
M |
Month number, 1-2 digits | 1 |
dd |
Day of month, 2 digits | 05 |
d |
Day of month, 1-2 digits | 5 |
yyyy |
4-digit year | 2025 |
yy |
Year (same as yyyy) |
2025 |
y |
Year (same as yyyy) |
2025 |
- Tokens are case-sensitive.
- Only the tokens above are supported.
You can use CLDR-style named patterns: "full", "long", "medium",
"short". These will be resolved to locale-appropriate patterns for the given
language.
| Pattern | English (en) | French (fr) |
|---|---|---|
| full | Sunday, January 5, 2025 | dimanche 5 janvier 2025 |
| long | January 5, 2025 | 5 janvier 2025 |
| medium | Jan 5, 2025 | 5 janv. 2025 |
| short | 1/5/25 | 05/01/2025 |
To include literal text in patterns, wrap it in single quotes ('). To
include a single quote, use '' (two single quotes).
| Example Pattern | Output |
|---|---|
'Today is' EEEE |
Today is Sunday |
yyyy'/'MM'/'dd |
2025/01/05 |
'''Quoted text''' |
'Quoted text' |
EEE 'the' dd |
Sun the 05 |
Datify supports all languages provided by datify-core. If you pass an unsupported language code, an error will be thrown.
- Native speakers wanted! If you notice missing or incorrect translations for a language, please contribute directly to datify-core, which manages all locale data for Datify.
- Pull requests for bug fixes, improvements, ideas, or feedback are welcome here.
- For upstream locale data and structure, see cldr-json.
MIT © 2025 Jeomhps CLDR data © Unicode, Inc., used under the Unicode License.
To run the full test suite locally, you have two options:
- Using tt (tytanic)
tt run
- Using act
act --artifact-server-path /tmp/artifact
- CLDR: Unicode Common Locale Data Repository, a project for locale-specific data (e.g., date formats, language rules).
- ISO 639-1: Two-letter codes for representing languages (e.g.,
enfor English,frfor French). - Typst: A markup-based typesetting system.