Novis\Intl\DateFormat::Fields
Which parts of a date DateFormat writes: the day, the month, the year and the day of the week.
DateFormat::Fields is declared in the class Novis\Intl\DateFormat.
You pass a DateFormat::Fields to DateFormat::dates or DateFormat::dateTimes as fields, beside length. Each case of the enum is one choice. In English for the United States, with DateFormat::Length::Long, Monday, January 5, 2026 is:
Day: "5".MonthDay: "January 5".YearMonthDay: "January 5, 2026". This is the default.Weekday: "Monday".DayWeekday: "5 Monday".MonthDayWeekday: "Monday, January 5".YearMonthDayWeekday: "Monday, January 5, 2026".Month: "January".YearMonth: "January 2026".Year: "2026".
The name of a case says which parts appear. The locale decides in which order they appear. In German, YearMonth gives "Januar 2026" and MonthDayWeekday gives "Montag, 5. Januar". The locale also decides the separators. In English, DayWeekday has no comma and gives "5 Monday".
Month, YearMonth and Year have no day. A time of day needs a day, so DateFormat::dateTimes throws a LogicError for these three cases. It throws before it formats any value. Use DateFormat::dates for them.
Good to know: length still applies. With the default DateFormat::Length::Medium, YearMonth gives "Jan 2026" in English.
Examples
Each part of a date
<?nvs// Shows one date written with each `DateFormat::Fields`, in English and in German.use Novis\Intl\DateFormat;
array<Core\Time\Date> $dates = [Core\Time\Date::at(2026, 1, 5)];array<DateFormat::Fields> $cases = [ DateFormat::Fields::Day, DateFormat::Fields::MonthDay, DateFormat::Fields::YearMonthDay, DateFormat::Fields::Weekday, DateFormat::Fields::DayWeekday, DateFormat::Fields::MonthDayWeekday, DateFormat::Fields::YearMonthDayWeekday, DateFormat::Fields::Month, DateFormat::Fields::YearMonth, DateFormat::Fields::Year,];
// The loop prints one line for each case: the English text, then `|`, then the German text.// The locale decides the order of the parts. `YearMonth` prints January 2026, then Januar 2026.foreach ($cases as DateFormat::Fields $fields) { var $options = { fields: $fields, length: DateFormat::Length::Long }; echo DateFormat::dates($dates, 'en-US', $options)[0], ' | ', DateFormat::dates($dates, 'de', $options)[0], "\n";}5 | 5January 5 | 5. JanuarJanuary 5, 2026 | 5. Januar 2026Monday | Montag5 Monday | Montag, 5.Monday, January 5 | Montag, 5. JanuarMonday, January 5, 2026 | Montag, 5. Januar 2026January | JanuarJanuary 2026 | Januar 20262026 | 2026Changelog
| Version | Change |
|---|---|
0.0.6 | Novis\Intl\DateFormat::Fields selects which parts of a date are shown, such as only the month and the year. The locale decides their order, so YearMonth shows Januar 2026 in de. |
