fdu logo@pyyupsk/fdu - Faster Date-Time Utility
Introduction

Quick Start

Get started with @pyyupsk/fdu in 5 minutes. Learn how to create dates, format output, manipulate dates, compare instances, and use localization with practical examples and code snippets.

Import

import { fdu } from "@pyyupsk/fdu";

Creating Dates

// Current date and time
const now = fdu();

// From ISO string
const date1 = fdu("2025-09-30");
const date2 = fdu("2025-09-30T14:30:00");

// From Date object
const date3 = fdu(new Date());

// From timestamp (milliseconds)
const date4 = fdu(1727704200000);

// From object
const date5 = fdu({ year: 2025, month: 9, day: 30 });

Formatting

const date = fdu("2025-09-30T14:30:45");

date.format("YYYY-MM-DD"); // '2025-09-30'
date.format("MMMM DD, YYYY"); // 'September 30, 2025'
date.format("dddd [at] HH:mm"); // 'Monday at 14:30'
date.format("hh:mm:ss A"); // '02:30:45 PM'
date.format("YYYY-MM-DDTHH:mm:ss"); // '2025-09-30T14:30:45'

See all format tokens →

Manipulation

All manipulation methods return a new instance (immutable):

const date = fdu("2025-09-30");

// Add time
date.add(1, "day"); // 2025-10-01
date.add(2, "month"); // 2025-11-30
date.add(1, "year"); // 2026-09-30
date.add(3, "hour"); // 2025-09-30T03:00:00

// Subtract time
date.subtract(1, "day"); // 2025-09-29
date.subtract(2, "month"); // 2025-07-30
date.subtract(1, "week"); // 2025-09-23

// Chaining (immutable)
const result = date.add(1, "month").subtract(2, "day").add(3, "hour");

Supported units: year, month, week, day, hour, minute, second, millisecond

Comparison

const date1 = fdu("2025-09-30");
const date2 = fdu("2025-10-01");

// Basic comparison
date1.isBefore(date2); // true
date1.isAfter(date2); // false
date1.isSame(date2); // false

// Unit-specific comparison
date1.isSame(date2, "month"); // true (same month)
date1.isSame(date2, "year"); // true (same year)
date1.isSame(date2, "day"); // false (different day)

// Calculate difference
date1.diff(date2, "day"); // -1
date1.diff(date2, "hour"); // -24
date1.diff(date2, "month"); // 0

Query

Get individual date/time components:

const date = fdu("2025-09-30T14:30:45.123");

date.year(); // 2025
date.month(); // 8 (0-indexed, September)
date.date(); // 30
date.day(); // Day of week (0-6, Sunday-Saturday)
date.hour(); // 14
date.minute(); // 30
date.second(); // 45
date.millisecond(); // 123

Months are zero-indexed (January = 0, December = 11), matching JavaScript's Date object behavior.

Conversion

const date = fdu("2025-09-30T14:30:45");

// Check validity
date.isValid(); // true

// Convert to Date object
date.toDate(); // Date object

// Convert to ISO string
date.toISOString(); // '2025-09-30T14:30:45.000Z'

// Get Unix timestamp (milliseconds)
date.valueOf(); // 1727704245000

// Get Unix timestamp (seconds)
date.unix(); // 1727704245

Localization

import { fdu, registerLocale, locale } from "@pyyupsk/fdu";
import { es } from "@pyyupsk/fdu/locale/es";

// Register locale
registerLocale("es", es);

// Set global locale
locale("es");

// Format with global locale
const date = fdu("2025-09-30");
date.format("dddd, D [de] MMMM [de] YYYY");
// 'martes, 30 de septiembre de 2025'

// Or use locale per instance
date.locale("es").format("MMMM YYYY"); // 'septiembre 2025'
date.locale("en").format("MMMM YYYY"); // 'September 2025'

See all available locales →

Plugins

Extend fdu with plugins for additional functionality:

Relative Time

import { fdu } from "@pyyupsk/fdu";
import { relativeTime } from "@pyyupsk/fdu/plugins/relative-time";

fdu.extend(relativeTime);

const date = fdu("2025-09-28");

date.fromNow(); // '2 days ago'
date.toNow(); // 'in 2 days'

Advanced Format

import { fdu } from "@pyyupsk/fdu";
import { advancedFormat } from "@pyyupsk/fdu/plugins/advanced-format";

fdu.extend(advancedFormat);

const date = fdu("2025-09-30");

date.quarter(); // 3 (Q3)
date.dayOfYear(); // 273
date.weekOfYear(); // 40
date.isoWeek(); // 40

See all plugins →

Common Patterns

Current date at midnight

const today = fdu().startOf("day");

End of month

const endOfMonth = fdu().endOf("month");

Check if weekend

const isWeekend = fdu().day() === 0 || fdu().day() === 6;

Format for API

const apiDate = fdu().format("YYYY-MM-DD");

Parse API response

const date = fdu("2025-09-30T14:30:45.000Z");

On this page