Date utils TypeScript helper for React
v1.0.0Added in 1.0.0
Locale-aware date helpers for React date pickers and calendars: week start, month and weekday names, typed-date parsing, grids and presets.
Pick a locale and the month grid reorders itself: Sunday first in en-US, Monday first in en-GB and ro-RO, Saturday first in ar-EG, with the names from Intl. Type a date the way people do (9/23, 23/9/26, tomorrow, +3) and see what it parses to. The preset list shows the usual report ranges for today.
Date utils is a Pro React helper in the React hooks and utilities category, written in TypeScript for React 19. It installs as source with npx wingo-ui@latest add date-utils, together with the npm package date-fns.
Add to a project
Requirements: React 19, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup
npx wingo-ui@latest add date-utilsDate utils is part of Pro, with 298 more Pro items: $8 a month or $150 once. 14-day refund before you download any Pro item. See plans
Usage
Import parseDate from @/lib/date-utils.
import { formatDate, getWeekStartsOn, parseDate } from "@/lib/date-utils"
const date = parseDate("9/23", { locale: "en-US" })
formatDate(date, "en-US") // "09/23/2026"
getWeekStartsOn("en-US") // 0 (Sunday)
getWeekStartsOn("ro-RO") // 1 (Monday)API
localedefault"en-US"stringThe demo's locale. Every helper takes an optional locale; pass the one from useLocale so server and browser agree.
textdefault""stringThe demo's typed date, parsed with parseDate in the locale (English keywords by default, Romanian ones such as maine when the locale is ro-RO).
parseDate(text: string, options?: { locale?: string; reference?: Date; keywords?: { today?, tomorrow?, yesterday?: string[] } }) => Date | nullA typed date or null. The locale's field order with . / - or spaces, 1 or 2 digit day and month, a 2 digit year (nearest century) or none (this year), ISO "2026-09-23" in any locale, keywords without case or diacritics, and "+3" / "-2" for days from today. 31.02 is rejected, never rolled over.
Parts
getWeekStartsOn
functionThe first day of the week for a locale, 0 (Sunday) to 6 like date-fns: 0 in en-US, 1 in en-GB and de-DE, 6 in ar-EG. From Intl week info where the browser has it, from a CLDR table where it does not (Firefox).
getWeekendDays
functionThe weekend days for a locale as weekday numbers: [6, 0] in en-US, [5, 6] in ar-EG. Calendars use it to tint weekends.
getHourCycle
functionWhether a locale writes times on a 12 hour ("h12", en-US) or 24 hour clock ("h23", en-GB, de-DE).
capitalize
functionUppercases the first letter in the locale's rules, for month names that Intl writes in lowercase in some languages.
getMonthNames
functionThe twelve month names from Intl, January first and capitalized, in "long", "short" or "narrow" form. No bundled locale data.
getWeekdayNames
functionWeekday names in display order from weekStartsOn, in "long", "short", "min" or "narrow" form. "min" is the two-letter calendar header (Su Mo Tu We Th Fr Sa).
formatMonthYear
functionThe calendar caption for a month: "September 2026" in en-US.
getDateOrder
functionHow a locale writes a numeric date: { order, separator, pattern }, e.g. MM/dd/yyyy in en-US and dd.MM.yyyy in de-DE.
autoFormatDateInput
functionInserts the locale's separators while someone types digits into a date field: "0923" becomes "09/23/" in en-US. Text with letters, like "tomorrow", passes through.
formatDate
functionA date in the locale, numeric by default ("09/23/2026" in en-US) or with any Intl options ({ dateStyle: "medium" } gives "Sep 23, 2026"). "" for null or an invalid date.
formatDateRange
functionA range through Intl formatRange, which writes the shared month and year only once. While only the start is picked it prints the start alone, followed by a dash.
formatDayLabel
functionThe long spoken form of a day for a day button's aria-label: "Wednesday, September 23, 2026".
toISODate
function"2026-09-23" in local time for hidden form inputs. Never uses toISOString, which converts to UTC and can land on the previous day.
toISODateTime
function"2026-09-23T14:30" in local time, for date and time inputs.
fromISODate
functionReads "2026-09-23" or "2026-09-23T14:30" back into a local Date; null when the text is not one.
matchesDate
functionWhether a day matches a DateMatcher or a list of them. Calendars use it for disabled and marked days.
getMonthWeeks
functionThe weeks of a month grid, 7 days each from weekStartsOn, including the neighbor month's days that fill the first and last week. fixedWeeks always returns 6 weeks so the grid never changes height.
normalizeRange
functionPuts from before to, swapping a range picked backwards. Nulls stay.
isInRange
functionWhether a day is inside a range, both ends included.
countDays
functionThe days in a range, both ends included (a 3 night hotel stay is 4 days); 0 while the range is incomplete.
getDatePresets
functionSingle-day presets from a reference day: today, tomorrow, yesterday, nextWeek (same weekday) and nextMonth. Labels are the picker's job.
getRangePresets
functionThe usual report ranges from a reference day, ends included: last 7 days, this month, last quarter and more. "Last 7 days" ends today.
parseTime
functionWhat someone typed as an "HH:mm" string, or null: "14:30", "1430", "14.30", "2:30 pm", "2p", "12am". Locale-free like <input type="time">.
formatTime
functionAn "HH:mm" value in the locale: "2:30 PM" in en-US, "14:30" in en-GB. hourCycle forces a 12 or 24 hour clock.
getDayPeriodLabels
functionThe locale's AM and PM labels, for a time picker's period toggle.
timeToMinutes
function"14:30" to 870 minutes after midnight; null when the value is not a time.
minutesToTime
function870 to "14:30", wrapping around midnight.
setTime
functionA new Date on the same day at an "HH:mm" time.
getTimeOfDay
functionThe "HH:mm" time of a Date.
DateRange
type{ from: Date | null; to: Date | null }, the value of range pickers.
DateMatcher
typeWhat a calendar can disable or mark: a Date, a Date[], { from, to }, { before }, { after }, { dayOfWeek } or (date) => boolean.
Weekday
type0 (Sunday) to 6 (Saturday), like date-fns.
ParseDateOptions
typeparseDate's options: locale, reference (the day "tomorrow" counts from) and keywords per language.
Examples
Week start by locale
Calendar headers and numeric date patterns straight from Intl.
Typed dates
parseDate in en-US with today fixed to Sep 23, 2026; Feb 31 is rejected, never rolled over.
Report ranges
getRangePresets with formatDateRange and countDays, both ends included.
Typed times
parseTime turns loose input into HH:mm; formatTime shows it per locale.
Dependencies
Files
- lib/date-utils.ts
FAQ
Is the Date utils helper free?
The preview, props and docs are free; copying the source needs a Pro plan. See plans.
How do I install Date utils?
Run npx wingo-ui@latest add date-utils. It also adds the npm package date-fns. With shadcn, add the @wingo-ui registry with your API key, then run npx shadcn@latest add @wingo-ui/date-utils.