Skip to content

icu-datetime

Info

This documentation is for version v0.2.0 of the package. If you want to see the latest version, go to nerixyz.github.io/icu-typ.

This library is a wrapper around ICU4X' datetime formatting for Typst which provides internationalized formatting for dates, times, and timezones.

If you're looking for documentation of an older version, append that version to the URL:

Usage

#import "@preview/icu-datetime:0.2.0": icu

This documentation was built on #icu.fmt(datetime.today()).
PreviewPreview

For detailed documentation, see fmt- Format Date and Time.

Date

#let day = datetime(
  year: 2024,
  month: 5,
  day: 31,
)

#icu.fmt(day, locale: "km", date-fields: "YMD") \
#icu.fmt(day, locale: "af", date-fields: "YMD") \
#icu.fmt(day, locale: "za", date-fields: "YMD") \
PreviewPreview

Time

#let time = datetime(
  hour: 18,
  minute: 2,
  second: 23,
)

#icu.fmt(time, locale: "id", time-precision: "second") \
#icu.fmt(time, locale: "en", time-precision: "second") \
#icu.fmt(time, locale: "ga", time-precision: "second") \
PreviewPreview

Date and Time

#let dt = datetime(
  year: 2024,
  month: 5,
  day: 31,
  hour: 18,
  minute: 2,
  second: 23,
)

#icu.fmt(dt, locale: "ru", length: "long") \
#icu.fmt(dt, locale: "en-US", length: "long") \
#icu.fmt(dt, locale: "zh-Hans-CN", length: "long") \
#icu.fmt(dt, locale: "ar", length: "long") \
#icu.fmt(dt, locale: "fi", length: "long")
PreviewPreview

Zones

#let tz = (
  offset: "-07",
  iana: "America/Los_Angeles",
)

#icu.fmt(
  datetime.today(), zone: tz,
  zone-style: "specific-long"
) \
#icu.fmt(
  datetime.today(), zone: tz,
  zone-style: "generic-short"
)
PreviewPreview

Zoned Datetimes

#let dt = datetime(
  year: 2024,
  month: 5,
  day: 31,
  hour: 18,
  minute: 2,
  second: 23,
)
#let tz = (
  offset: "-07",
  iana: "America/Los_Angeles",
)
#let opts = (
  zone: tz,
  date-fields: "YMDE",
  time-precision: "second",
  length: "long"
)

#icu.fmt(dt, ..opts, zone-style: "generic-short") \
#icu.fmt(dt, ..opts,
  zone-style: "localized-offset-short",
  locale: "lv"
) \
#icu.fmt(dt, ..opts,
  zone-style: "exemplar-city",
  locale: "en-CA-u-hc-h24-ca-buddhist"
)
PreviewPreview