Sub topic 5
Plain Dates and Times Without Time Zones
This chapter assumes you can run ES modules in Node.js or a browser and that Temporal is available, either natively or through the polyfill set up in an earlier chapter. You should also know the difference between exact time and wall-clock time from the types overview.
A plain type holds a wall-clock value with no time zone attached. "March 15" or "9:30 in the morning" means the same thing wherever you read it, so the value carries no offset and points to no exact moment. Use plain types for birthdays, store opening hours, and due dates, where tying the value to a time zone would change its meaning.
The Five Plain Types
| Type | Holds | Example string | Typical use |
|---|---|---|---|
| `PlainDate` | year, month, day | `2024-03-15` | Due dates, birthdays |
| `PlainTime` | hour down to nanosecond | `09:30:00` | Daily alarm, opening time |
| `PlainDateTime` | date plus time | `2024-03-15T09:30:00` | Local event before a zone is known |
| `PlainYearMonth` | year, month | `2024-02` | Billing periods, card expiry |
| `PlainMonthDay` | month, day | `12-25` | Yearly holidays, anniversaries |
Working With Each Type
Every type exposes its fields as read-only properties. Each one also has computed properties such as dayOfWeek and daysInMonth.
const date = Temporal.PlainDate.from('2024-03-15');
const time = Temporal.PlainTime.from('09:30');
const meeting = date.toPlainDateTime(time);
console.log(meeting.toString()); // '2024-03-15T09:30:00'
console.log(meeting.hour); // 9
const billing = Temporal.PlainYearMonth.from('2024-02');
console.log(billing.daysInMonth); // 29
const christmas = Temporal.PlainMonthDay.from({ month: 12, day: 25 });
const thisYear = christmas.toPlainDate({ year: 2025 });
console.log(thisYear.toString()); // '2025-12-25'
console.log(thisYear.dayOfWeek); // 4 (Thursday)PlainYearMonth and PlainMonthDay are partial values. To get a full date, supply the missing field, as toPlainDate({ year }) does above.
Common Errors
- Using PlainDateTime for timestamps. Log entries and created-at fields need
InstantorZonedDateTime. A plain value loses the information about where it was recorded. - Assuming a month-day exists every year. February 29 is a valid
PlainMonthDay. In a non-leap year,toPlainDate({ year: 2025 })clamps it to2025-02-28. - Mixing types in methods.
PlainDate.prototype.equalsexpects a date-like value. Comparing a date to a date-time means you first pick which parts you care about, for example withmeeting.toPlainDate().
const leapDay = Temporal.PlainMonthDay.from({ month: 2, day: 29 });
console.log(leapDay.toPlainDate({ year: 2025 }).toString()); // '2025-02-28'Exercise
A gym is open from 06:00 to 22:00 every day, and each member's membership renews on the same day each month. Which plain type fits the opening hours, and which fits a member's renewal billing period?
Show answer
The opening hours are two PlainTime values, because they repeat daily with no date. The billing period is a PlainYearMonth, because a charge applies to a whole month of a given year and needs no day or time.
Exercise
What does Temporal.PlainDate.from('2024-03-15').toPlainMonthDay().toPlainDate({ year: 2026 }).toString() return?
Show answer
'2026-03-15'. The month and day are kept, and the year is replaced with 2026.