Package limn.i18n

Class DateFormats

java.lang.Object
limn.i18n.DateFormats

public final class DateFormats extends Object
Ready-made date and time formats, beside NumberFormats: what a table puts in a date column, and what any caption that shows a day or an hour can use.

Every format here follows the language in effect where it formats, read at that moment, as NumberFormats' do: the order of day, month and year, the separators and a month's name are the language's, and a widget inside a subtree that declares its own locale formats in that subtree's language. The digits are the toolkit's, the numbering system's, as every number it writes: the platform writes a date in ASCII digits whatever the language, so under ar-EG a date beside an amount read 17/10/2026 next to ١٬٢٣٤٫٥, where these write ١٧/١٠/٢٠٢٦.


 Column.of("Due", Order::due, DateFormats.date(FormatStyle.SHORT));  // "10/17/26", "17/10/2026"
 label.setText(DateFormats.time(FormatStyle.SHORT).apply(at));       // "2:09 PM", "14:09"
 

The calendar is the locale's. A locale that names a calendar system with the Unicode extension -u-ca-, as a user's settings write a choice of calendar, is written in it, as the date widgets draw it: ja-JP-u-ca-japanese writes the era ("R7/10/25"), th-TH-u-ca-buddhist the Buddhist year (2568), ar-SA-u-ca-islamic-umalqura the Hijri date. The value is the same LocalDate either way; only how it is written changes. A calendar the platform does not carry is read as none, and a locale that names none is written in the ISO calendar, which is what the platform answers for every language without one. A day the named calendar does not reach is written in the ISO calendar too, as the date widgets draw it: the platform's Umm al-Qura calendar covers 1882 to 2174 and its Japanese one nothing before 1873, so a 9999-12-31 that stands for "no end date" is written under ar-SA-u-ca-islamic-umalqura as the ISO date it is, where the platform refuses it. That holds for every style, and for the date in a date and time, and the time of day alone of one.

A format takes any temporal that holds the fields it writes: a LocalDate for a date, a LocalTime for a time, a LocalDateTime for both, and a zoned or offset one for any of them. One that lacks a field the format writes is refused by the platform with a DateTimeException.

  • Method Details

    • date

      public static Function<TemporalAccessor,String> date(FormatStyle style)
      A date at style's length: SHORT writes 10/17/26 in English and 17/10/2026 in Brazilian Portuguese, MEDIUM writes Oct 17, 2026, and LONG and FULL write the month, and the weekday, in words.
      Parameters:
      style - how long the date is written; never null
      Returns:
      the format
    • time

      public static Function<TemporalAccessor,String> time(FormatStyle style)
      A time of day at style's length: SHORT writes 2:09 PM in English and 14:09 in Brazilian Portuguese, MEDIUM adds the seconds.
      Parameters:
      style - SHORT or MEDIUM; never null
      Returns:
      the format
      Throws:
      IllegalArgumentException - for LONG or FULL, which write a time zone that a time of day does not have, and which the platform would refuse only when the first value was formatted
    • dateTime

      public static Function<TemporalAccessor,String> dateTime(FormatStyle style)
      A date and a time of day, both at style's length: SHORT writes 10/17/26, 2:09 PM in English and 17/10/2026, 14:09 in Brazilian Portuguese.
      Parameters:
      style - SHORT or MEDIUM; never null
      Returns:
      the format
      Throws:
      IllegalArgumentException - for LONG or FULL, as time(java.time.format.FormatStyle) does