Bookmark this: tool.io/parse/date/source-code
Date Parser Source Code
Browse the implementation files for Date Parser.tool.ts typescript
import {
parseCalendarDate as parsePortableCalendarDate,
type CalendarDateFormat,
type ParsedCalendarDate
} from '@tool.io/tools/parse/date';
export type { CalendarDateFormat, ParsedCalendarDate };
const DATE_FORMATS = ['de-DE', 'en-US', 'iso'] as const;
export const parseCalendarDate = (
input: unknown,
formatInput: unknown = 'iso'
): ParsedCalendarDate | null => {
if (
typeof input !== 'string' ||
typeof formatInput !== 'string' ||
!DATE_FORMATS.includes(formatInput as CalendarDateFormat)
) {
return null;
}
return parsePortableCalendarDate(
input,
formatInput as CalendarDateFormat
);
};
export const normalizeCalendarDate = (
input: unknown,
formatInput: unknown = 'iso'
): string => parseCalendarDate(input, formatInput)?.iso ?? '';
export const Tool: TypeTool = {
name: 'Date Parser',
slug: 'parse/date',
intro:
'Parse a calendar date in an explicit format and return an ISO date.',
tool: normalizeCalendarDate,
i: [
{
example: '2026-08-11',
label: 'Date',
placeholder: 'Enter a calendar date',
type: 'text'
},
{
example: 'iso',
label: 'Date Format',
options: [
{ text: 'ISO (YYYY-MM-DD)', value: 'iso' },
{ text: 'US (MM/DD/YYYY)', value: 'en-US' },
{ text: 'German (DD.MM.YYYY)', value: 'de-DE' }
],
placeholder: 'Choose a date format',
type: 'select',
value: 'iso'
}
],
o: [
{
example: '2026-08-11',
label: 'ISO Date',
placeholder: 'ISO date will appear here...',
render: 'textarea',
type: 'text'
}
]
};
export default Tool;
Description
Browse the implementation files for Date Parser.