Temporal API compatibility layer

Import

import { ... } from 'ts-time-utils/temporal';

Examples

Temporal-like Objects

Future-proof with Temporal-inspired API

import {
  toPlainDate, toPlainDateTime, toZonedDateTime, toInstant
} from 'ts-time-utils/temporal';

// PlainDate - date without time
const date = toPlainDate(2025, 9, 14);
console.log(date.year, date.month, date.day);
// 2025, 9, 14

console.log(date.dayOfWeek);    // 7 (Sunday, ISO)
console.log(date.dayOfYear);    // 257
console.log(date.weekOfYear);   // 37

// Date arithmetic
const nextWeek = date.add({ days: 7 });
console.log(nextWeek.toString()); // "2025-09-21"

const diff = date.until(nextWeek);
console.log(diff.days); // 7

// PlainDateTime - date with time, no timezone
const dt = toPlainDateTime(2025, 9, 14, 10, 30, 0);
console.log(dt.hour, dt.minute); // 10, 30

// ZonedDateTime - date with timezone
const zdt = toZonedDateTime(new Date(), 'America/New_York');
console.log('NY hour:', zdt.hour);
console.log('Timezone:', zdt.timeZone);

// Convert to different zone
const tokyo = zdt.withTimeZone('Asia/Tokyo');
console.log('Tokyo hour:', tokyo.hour);

// Instant - epoch-based moment in time
const instant = toInstant(Date.now());
console.log('Epoch ms:', instant.epochMilliseconds);

const inUTC = instant.toZonedDateTime('UTC');
console.log('UTC:', inUTC.toString());