Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/react-calendar. Ultimate calendar for your React app. projects.wojtekmaj.pl/react-calendar
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import { getISOLocalDate } from '../../src/shared/dates';
const hourOptionalSecondsRegExp = /^(([0-1])?[0-9]|2[0-3]):[0-5][0-9](:([0-5][0-9]))?$/;const hourRegExp = /^(([0-1])?[0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9])$/;
export const getHours = (date) => { if (date instanceof Date) { return date.getHours(); }
if (typeof date === 'string' && hourOptionalSecondsRegExp.test(date)) { const [hourString] = date.split(':'); return parseInt(hourString, 10); }
throw new Error(`Failed to get hours from date: ${date}.`);};
export const getMinutes = (date) => { if (date instanceof Date) { return date.getMinutes(); }
if (typeof date === 'string' && hourOptionalSecondsRegExp.test(date)) { const [, minuteString] = date.split(':'); return parseInt(minuteString, 10); }
throw new Error(`Failed to get minutes from date: ${date}.`);};
export const getSeconds = (date) => { if (date instanceof Date) { return date.getSeconds(); }
if (typeof date === 'string') { if (hourRegExp.test(date)) { const [, , secondString] = date.split(':'); return parseInt(secondString, 10); }
if (hourOptionalSecondsRegExp.test(date)) { return 0; } }
throw new Error(`Failed to get seconds from date: ${date}.`);};
export const getHoursMinutesSeconds = (date) => { if (!date) { return date; }
const hours = `0${getHours(date)}`.slice(-2); const minutes = `0${getMinutes(date)}`.slice(-2); const seconds = `0${getSeconds(date)}`.slice(-2);
return `${hours}:${minutes}:${seconds}`;};
export const getISOLocalDateTime = (value) => { if (!value) { return value; }
const date = new Date(value);
if (isNaN(date.getTime())) { throw new Error(`Invalid date: ${value}`); }
return `${getISOLocalDate(date)}T${getHoursMinutesSeconds(date)}`;};