Overview

date(input?) returns a MatesDate — a branded timestamp with methods for formatting, relative time, arithmetic, age, and predicates. No external date library required.

Configure locale and timezone with setLocale, setTimezone, and setTimezoneOffset. Calendar helpers getMonths / getCalendar build locale-aware month labels and week grids.

Factory vs calendar helpers

API
Returns
Notes
date(input?) MatesDate Format, arithmetic, predicates
getCalendar(y, m) MatesDate[][] Sunday-start week rows
getMonths() MonthInfo[] Localised month names

Live date() demo

Pick any date to see formatting, relative time, and arithmetic update in real time.

import { html, atom, renderApp, date } from 'mates';

const App = () => {
const selected = atom(date().format('YYYY-MM-DD'));

return () => {
const d = date(selected() + 'T12:00:00');
const yesterday = date(selected() + 'T12:00:00').subtract(1, 'days');
const tomorrow = date(selected() + 'T12:00:00').add(1, 'days');
const nextWeek = date(selected() + 'T12:00:00').add(7, 'days');

return html`
<div class="m-col m-gap">
<label class="m-col m-gap-xs">
Pick a date:
<input type="date"
.value=${selected()}
@change=${e => selected.set(e.target.value)}
/>
</label>
<div class="m-grid m-grid-cols-3 m-gap">
<div class="card card-body center">
<span class="overline">Formatted</span>
<span class="card-title">${d.format('MMM D, YYYY')}</span>
</div>
<div class="card card-body center">
<span class="overline">Relative</span>
<span class="card-title">${d.formatLongAgo()}</span>
</div>
<div class="card card-body center">
<span class="overline">Is today?</span>
<span class="card-title">${d.isToday() ? '✓ Yes' : '✗ No'}</span>
</div>
</div>
<div class="card card-body m-col m-gap">

getCalendar month grid

Week rows of MatesDate for the selected month — today highlighted.

import { html, atom, renderApp, date, getMonths, getCalendar } from 'mates';

const App = () => {
const month = atom(date().values.month);
const year = atom(date().values.year);

return () => {
const months = getMonths();
const weeks = getCalendar(year(), month());
const label = months[month() - 1]?.name ?? '';

return html`
<div class="m-col m-gap">
<div class="m-flex m-items-center m-justify-center m-gap-sm">
<button @click=${() => month.set(m => m === 1 ? 12 : m - 1)}>‹</button>
<span class="muted">${label} ${year()}</span>
<button @click=${() => month.set(m => m === 12 ? 1 : m + 1)}>›</button>
</div>
${weeks.map(week => html`
<div class="m-flex m-gap-sm m-items-center">
${week.map(d => html`
<span class="tag ${d.isToday() ? 'tag-primary' : ''}">
${d.values.date}
</span>
`)}
</div>
`)}
</div>
`;
};
};
renderApp(App, document.getElementById('app'));