# Types of time

Pick the right type for a calendar day, a time of day, a specific moment, a partial date, a range, or a length of time.

JavaScript's built-in `Date` uses one object for everything, whether you mean someone's birthday, a 9:30 AM alarm, or the exact second an order was placed.

Each concept gets its own type so you only work with the parts you actually have:

- **[`CalendarDate`](/api/calendar-date/)** for a day on the calendar, like May 10, 2026
- **[`Time`](/api/time/)** for a time of day, like 9:30 AM
- **[`DateTime`](/api/date-time/)** for a specific moment in a time zone
- **[`Duration`](/api/duration/)** for a length of time, like 2 hours or 3 weeks
- **[`YearMonth`](/api/year-month/)** and **[`MonthDay`](/api/month-day/)** for a month without a day, or a recurring day without a year
- **[Ranges](/api/ranges/)** for a span between two dates, times, or moments

## CalendarDate

Use [`CalendarDate`](/api/calendar-date/) when something happens on a day rather than at a specific second: birthdays, due dates, holidays, or values from a date picker.

Create one with [`today()`](/api/date-fn/#today) or [`date()`](/api/date-fn/):

```js
import { date, today } from 'native-dates';

const birthday = date('2026-05-10');
const due = today().plus(2, 'weeks');

birthday.month; // 5
birthday.day; // 10
```

Because a calendar date has no clock or time zone, May 10 stays May 10 for every user regardless of where they live.

## Time

Use [`Time`](/api/time/) for a time of day that isn't tied to one specific date, such as store opening hours or a daily reminder.

```js
import { time } from 'native-dates';

const opens = time('9:00am');
const closes = opens.plus(8, 'hours');

closes.hour; // 17
closes.format('short', 'en-US'); // '5:00 PM'
```

Adding hours past midnight wraps around the 24-hour clock cleanly, since there is no date to advance.

## DateTime

Use [`DateTime`](/api/date-time/) when something happens at a real point in time: a meeting, a flight departure, or a timestamp from your database.

Create one with [`now()`](/api/datetime-fn/#now) or [`datetime()`](/api/datetime-fn/), or attach a time to a calendar date:

```js
import { date, datetime, now } from 'native-dates';

const current = now();
const created = datetime('2026-11-16T17:30:00Z');
const standup = date('2026-11-16').at('9:30am', 'America/Los_Angeles');
```

Each moment knows both when something happens and which time zone you're viewing it in. Call [`in()`](/api/date-time/#in) to see that same moment in another city:

```js
standup.in('Europe/Berlin').format('time', 'en-US'); // '6:30 PM'
```

## Duration

Use [`Duration`](/api/duration/) for how long something lasts. Create one with unit helpers like [`hours()`](/api/duration-fn/#hours) or pass a phrase to [`duration()`](/api/duration-fn/):

```js
import { days, duration, hours } from 'native-dates';

const call = hours(1.5);
const trial = days(14);
const turnaround = duration('2 weeks, 3 days');
```

Measuring the gap between two values returns a duration too:

```js
const opens = time('9:00am');
const lunch = time('12:30pm');

opens.until(lunch).format('long', 'en-US'); // '3 hours, 30 minutes'
```

## YearMonth

Use [`YearMonth`](/guides/months-and-days/#billing-months-and-card-expiries) when a value has a year and a month with no day, such as a billing period, a card expiry, or a month input.

```js
import { monthYear, yearMonth } from 'native-dates';

const billing = yearMonth('2026-11');
const expiry = monthYear('11/28');

billing.daysInMonth; // 30
billing.on(15); // CalendarDate for 2026-11-15
```

It counts in months and years, and [`on()`](/api/year-month/#on) picks any day inside that month as a calendar date.

## MonthDay

Use [`MonthDay`](/guides/months-and-days/#birthdays-and-annual-holidays) for a recurring date without a year, such as a birthday or an annual holiday.

```js
import { monthDay } from 'native-dates';

const birthday = monthDay('10/17');

birthday.in(2026); // CalendarDate for 2026-10-17
birthday.fallsOn('2026-10-17'); // true
```

February 29 lands on February 28 in non-leap years automatically when you call [`fallsOn()`](/api/month-day/#fallson) or [`in()`](/api/month-day/#in).

## Ranges

Use [Ranges](/guides/ranges/) for a span between two dates, times, or moments. Create one directly with [`dateRange()`](/api/range-fn/#daterange), [`timeRange()`](/api/range-fn/#timerange), or [`datetimeRange()`](/api/range-fn/#datetimerange):

```js
import { dateRange, timeRange } from 'native-dates';

const sprint = dateRange('2026-11-02', '2026-11-15');
const shift = timeRange('9:00am', '5:00pm');

sprint.contains('2026-11-10'); // true
shift.duration.hours; // 8
```

Date ranges include their final day, while moment and time ranges exclude their end boundary so back-to-back slots never overlap.

## Moving between them

These types connect directly when you add or drop parts. Attach a time to a calendar date with [`at()`](/api/calendar-date/#at) to get a moment, or span from an existing point with [`for()`](/api/ranges/#to) or [`to()`](/api/ranges/#to):

```js
const reminder = today().plus(1, 'day').at('9:00am');
const upcoming = today().for(2, 'weeks');
```

Going the other way, read part properties directly off any moment or date, or call [`as()`](/api/date-time/#as) inside a method chain:

```js
reminder.date; // CalendarDate for tomorrow
reminder.time; // Time for 09:00:00
reminder.yearMonth; // YearMonth
reminder.monthDay; // MonthDay
reminder.in('Asia/Tokyo').as('time'); // Time in Tokyo
```

:::tip[DateTime or CalendarDate?]
Ask whether changing time zones should change what the user sees. A 9:30 AM call in Los Angeles is 6:30 PM in Berlin, so it belongs in `DateTime`. A birthday on May 10 is still May 10 everywhere, so it belongs in `CalendarDate`.
:::
