struct-ui-components
Version:
A collection of reusable, customizable React components built with TypeScript, Tailwind CSS, and Storybook. Designed for modern UI development with flexibility and scalability.
56 lines (52 loc) • 1.96 kB
text/typescript
// localeMatcher?: 'best fit' | 'lookup';
// weekday?: 'long' | 'short' | 'narrow';
// era?: 'long' | 'short' | 'narrow';
// year?: 'numeric' | '2-digit';
// month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
// day?: 'numeric' | '2-digit';
// hour?: 'numeric' | '2-digit';
// minute?: 'numeric' | '2-digit';
// second?: 'numeric' | '2-digit';
// timeZoneName?: 'long' | 'short';
// formatMatcher?: 'best fit' | 'basic';
// hour12?: boolean;
// /**
// * Timezone string must be one of IANA. UTC is a universally required recognizable value
// */
// timeZone?: 'UTC' | string;
// dateStyle?: 'full' | 'long' | 'medium' | 'short',
// timeStyle?: 'full' | 'long' | 'medium' | 'short',
// calendar?: 'buddhist' | 'chinese' | ' coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | ' hebrew' | 'indian' | 'islamic' | 'iso8601' | ' japanese' | 'persian' | 'roc',
// dayPeriod?: 'narrow' | 'short' | 'long',
// numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | ' gujr' | 'guru' | 'hanidec' | 'khmr' | ' knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | ' mong' | 'mymr' | 'orya' | 'tamldec' | ' telu' | 'thai' | 'tibt',
// hourCycle?: 'h11' | 'h12' | 'h23' | 'h24',
// /**
// * Warning! Partial support
// */
// fractionalSecondDigits?: 0 | 1 | 2 | 3
// hh:mm
export const getTime = (dateString: string) => {
const date = new Date(dateString);
if (date.toString() === "Invalid Date") {
return "NA";
}
const timeFormatter = new Intl.DateTimeFormat(undefined, {
hour: "2-digit",
minute: "2-digit",
hour12: true, // Use 24-hour format
});
return timeFormatter.format(date);
};
// mm:dd:yyy
export const getDate = (dateString: string) => {
const date = new Date(dateString);
if (date.toString() === "Invalid Date") {
return "NA";
}
const timeFormatter = new Intl.DateTimeFormat(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
return timeFormatter.format(date);
};