UNPKG

@zohodesk/hooks

Version:

Unified Component Library - Hooks

43 lines 1.12 kB
export function timeEncode(_ref) { let { hours, minutes, noon } = _ref; return `${hours}:${minutes}:${noon}`; } export function timeDecode(data) { let time = data.split(':'); return { hours: time[0].toString().padStart(2, '0'), minutes: time[1].toString().padStart(2, '0'), noon: time[2] ? time[2] : undefined }; } export function timeDecode12(data) { let { hours, minutes, noon } = timeDecode(data); let hour = Number(hours) > 12 ? Number(hours) - 12 : hours; let nValue = noon && noon != '00' ? noon : Number(hours) > 12 ? 'PM' : 'AM'; return { hours: hour.toString().padStart(2, '0'), minutes: minutes.toString().padStart(2, '0'), noon: nValue }; } export function timeDecode24(data) { let { hours, minutes, noon } = timeDecode(data); let hour = noon == 'PM' && hours == 24 ? "00" : noon == 'PM' && Number(hours) <= 12 ? Number(hours) + 12 : noon == 'AM' && Number(hours) > 12 ? hours - 12 : hours; return { hours: hour.toString().padStart(2, '0'), minutes: minutes.toString().padStart(2, '0'), noon: "00" }; }