UNPKG

rsuite

Version:

A suite of react components

28 lines (27 loc) 675 B
'use client'; import { getHours } from 'date-fns/getHours'; import { getMinutes } from 'date-fns/getMinutes'; import { getSeconds } from 'date-fns/getSeconds'; import { set } from 'date-fns/set'; import { isValid } from 'date-fns/isValid'; /** * Copy the time from one date to another. * * @param from - The source date. * @param to - The target date. * @returns The target date with the time copied from the source date. */ export function copyTime({ from, to }) { if (!isValid(from) || !isValid(to)) { return to; } return set(to, { hours: getHours(from), minutes: getMinutes(from), seconds: getSeconds(from) }); } export default copyTime;