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'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"); // 0Query
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(); // 123Months 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(); // 1727704245Localization
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'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(); // 40Common 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");Installation
Install @pyyupsk/fdu using npm, pnpm, yarn, or bun. Get started with the ultra-fast, zero-dependency date-time library for TypeScript and JavaScript with CDN options and version information.
TypeScript Guide
Comprehensive TypeScript guide for @pyyupsk/fdu. Learn about full type inference, strict null safety, custom type guards, locale typing, plugin development with TypeScript, and advanced typing patterns for type-safe date manipulation.