Day

Day utilities for fast, time zone aware date operations.

addDays

Adds a number of days to a timestamp.

reference/day/addDays.ts
import { addDays, type TimeZone, toISOString } from "datezone";

// Current timestamp
const now = Date.now();

// Example timeZone that observes daylight-saving time
const timeZone: TimeZone = "America/New_York";

// Add 5 calendar days in the given timeZone
const inFiveDays = addDays(now, 5, timeZone);

console.log(`Now: ${toISOString(now, timeZone)}`);
console.log(`In 5 days (${timeZone}): ${toISOString(inFiveDays, timeZone)}`);

subDays

Subtracts a number of days from a timestamp.

reference/day/subDays.ts
import { subDays, type TimeZone, toISOString } from "datezone";

const tz: TimeZone = "Europe/London";
const now = Date.now();

// Go back 7 days in the given timeZone
const lastWeek = subDays(now, 7, tz);

console.log(`Last week in ${tz}: ${toISOString(lastWeek, tz)}`);

startOfDay

Returns the start of the day (00:00:00.000) in the given timezone.

reference/day/startOfDay.ts
import { startOfDay, type TimeZone, toISOString } from "datezone";

const tz: TimeZone = "Asia/Tokyo";
const now = Date.now();

const start = startOfDay(now, tz);

console.log(`Start of day in ${tz}: ${toISOString(start, tz)}`);

endOfDay

Returns the end of the day (23:59:59.999) in the given timezone.

reference/day/endOfDay.ts
import { endOfDay, type TimeZone, toISOString } from "datezone";

const tz: TimeZone = "UTC";
const now = Date.now();

const end = endOfDay(now, tz);

console.log(`End of UTC day: ${toISOString(end, tz)}`);

dayOfMonth

Returns the day of the month (1-31) in the given timezone.

reference/day/dayOfMonth.ts
import { dayOfMonth, type TimeZone } from "datezone";

const ts = Date.UTC(2024, 5, 21, 12); // 2024-06-21T12:00:00.000Z

console.log(dayOfMonth(ts, null)); // 21

const tz: TimeZone = "Asia/Tokyo";
console.log(dayOfMonth(ts, tz)); // 21

dayOfWeek

Returns the ISO day of week (1=Monday, 7=Sunday) in the given timezone.

Compability

For Compability with Javascript Date more details, see getDay.

reference/day/dayOfWeek.ts
import { dayOfWeek, type TimeZone } from "datezone";

// July 7, 2024 is a Sunday (ISO 7)
const ts = Date.UTC(2024, 6, 7);

console.log(dayOfWeek(ts, null)); // 7

const tz: TimeZone = "America/Los_Angeles";
console.log(dayOfWeek(ts, tz)); // 7

dayOfWeekBase

Returns the ISO day of week (1=Monday, 7=Sunday) in the given timezone.

reference/day/dayOfWeekBase.ts
import { dayOfWeekBase } from "datezone";

// ISO day of week: 1 (Mon) ... 7 (Sun)
console.log(dayOfWeekBase(2024, 7, 4)); // Independence Day 2024 → Thursday (4)
console.log(dayOfWeekBase(2024, 7, 7)); // Sunday → 7

dayOfYear

Returns the day of year (1-366) in the given timezone.

reference/day/dayOfYear.ts
import { dayOfYear, type TimeZone } from "datezone";

// March 1, 2024 (leap year)
const ts = Date.UTC(2024, 2, 1);

console.log(dayOfYear(ts, null)); // 61

const tz: TimeZone = "America/New_York";
console.log(dayOfYear(ts, tz)); // 61

dayOfYearBase

Calculates the ISO day-of-year (1-366) for a plain calendar date (year, month, day) without needing a timestamp.

reference/day/dayOfYearBase.ts
import { dayOfYearBase } from "datezone";

// December 31, 2024 (leap year) → 366th day
console.log(dayOfYearBase(2024, 12, 31)); // 366

weekDayName

Returns the localized weekday name.

reference/day/weekDayName.ts
import { weekDayName } from "datezone";

// Localized weekday names
console.log(weekDayName("en-US", "long", 1)); // "Monday"
console.log(weekDayName("en-US", "short", 5)); // "Fri"
console.log(weekDayName("ja-JP", "narrow", 7)); // "日"

getDayPeriod

Returns the localized day period (AM/PM) string for the given hour.

reference/day/getDayPeriod.ts
import { getDayPeriod } from "datezone";

console.log(getDayPeriod("en-US", 9)); // AM
console.log(getDayPeriod("en-US", 15)); // PM
console.log(getDayPeriod("fr-FR", 23)); // PM in French locale

getDay

Returns the day of the week for a given date (0 = Sunday, 6 = Saturday). This is a compability shortcut for dayOfWeek to be consistent with other date libraries. and is using Javascript standard instad of ISO 8601. Sunday is 0 and Saturday is 6.

reference/day/getDay.ts
// Example usage of the 'getDay' export from datezone
import { getDay } from "datezone";

const timestamp = Date.UTC(2024, 0, 1, 12, 10, 15);
console.log("Day of week:", getDay(timestamp, "Europe/Stockholm")); // 6 = Saturday

Compability

For ISO 8601 standard, use dayOfWeek instead.

On this page