glintl
Format dates and times in many languages, on Erlang and JavaScript.
import glintl
import glintl/locale/en_gb
import gleam/time/duration
import gleam/time/timestamp
let formatter =
glintl.date_time_formatter(en_gb.locale(), date: glintl.Long, time: glintl.Short)
glintl.format(formatter, timestamp.system_time(), offset: duration.hours(1))
// -> "25 October 2026 at 23:40"
On Erlang the formats come from data baked into this package, made from
ICU when the package is built. On JavaScript the runtime’s own
Intl.DateTimeFormat is used, so the output can differ slightly between
targets and between JavaScript runtimes.
Types
The calendars glintl can format dates in.
Each locale has a default: most use Gregorian, Thai uses Buddhist,
Persian uses Persian, and Saudi Arabic uses IslamicUmmAlQura.
On Erlang, calendars with their own months work for years 1 to 4000 of
the Gregorian calendar, and dates outside that are written in the
Gregorian calendar instead. These are every calendar but Gregorian,
Iso8601, Buddhist, Japanese and RepublicOfChina.
pub type Calendar {
Gregorian
Iso8601
Buddhist
Japanese
RepublicOfChina
Persian
Indian
Hebrew
Chinese
Dangi
Coptic
Ethiopic
EthiopicAmeteAlem
IslamicCivil
IslamicTabular
IslamicUmmAlQura
}
Constructors
-
Gregorian -
Iso8601The Gregorian calendar, with ISO 8601 rules for weeks and patterns.
-
BuddhistThe Thai solar calendar: Gregorian, with years counted from 543 BC.
-
JapaneseGregorian, with years counted in Japanese eras.
-
RepublicOfChinaThe Minguo calendar used in Taiwan: Gregorian, with years counted from 1912.
-
PersianThe Solar Hijri calendar used in Iran and Afghanistan.
-
IndianThe Indian national calendar.
-
Hebrew -
Chinese -
DangiThe Korean calendar.
-
Coptic -
EthiopicThe Ethiopian calendar, with years counted in the Amete Mihret era.
-
EthiopicAmeteAlemThe Ethiopian calendar, with years counted in the Amete Alem era.
-
IslamicCivilThe tabular Islamic calendar, counting from 16 July 622 in the Julian calendar, as civil tables do.
-
IslamicTabularThe tabular Islamic calendar, counting from 15 July 622 in the Julian calendar, the astronomical start.
-
IslamicUmmAlQuraThe Umm al-Qura calendar used in Saudi Arabia.
Formats moments in time for one locale and style.
Make one and reuse it: making a formatter does the lookup work once, so formatting is cheap.
pub opaque type Formatter
A language and region to format for, such as British English.
Get one from a locale module, like glintl/locale/en_gb, or by tag from
glintl/locales.
pub opaque type Locale
How much detail to show, from most to least.
These are the same as the dateStyle and timeStyle options of
JavaScript’s Intl.DateTimeFormat. In British English:
| Style | Date | Time |
|---|---|---|
Full | Sunday, 25 October 2026 | 23:40:58 GMT+01:00 |
Long | 25 October 2026 | 23:40:58 GMT+1 |
Medium | 25 Oct 2026 | 23:40:58 |
Short | 25/10/2026 | 23:40 |
pub type Style {
Full
Long
Medium
Short
}
Constructors
-
Full -
Long -
Medium -
Short
Values
pub fn date_time_formatter(
locale: Locale,
date date: Style,
time time: Style,
) -> Formatter
Format both the date and the time.
pub fn format(
formatter: Formatter,
timestamp: timestamp.Timestamp,
offset offset: duration.Duration,
) -> String
Format a moment in time, as seen from a place offset ahead of UTC.
The offset is rounded down to whole minutes. Time zones are written as a
GMT offset, like GMT+1, as glintl knows the offset but not the zone’s
name.
pub fn locale_tag(locale: Locale) -> String
The BCP 47 tag of a locale, such as "en-GB".