Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @flow
- export type TimePeriod = 'am' | 'pm';
- export type TimeOfTheDay = { hour: number, minute: number, period: TimePeriod };
- const getTimeOfTheDay = (date: Date): TimeOfTheDay => ({
- hour: date.getHours() > 12 ? date.getHours() - 12 : date.getHours(),
- minute: date.getMinutes(),
- period: date.getHours() >= 12 ? 'pm' : 'am',
- });
- const dateToPeriod = (startTime: Date, endTime: Date): string => {
- const time = [];
- const start = getTimeOfTheDay(startTime);
- const end = getTimeOfTheDay(endTime);
- time.push(`${start.hour}:${start.minute}`);
- time.push(`${end.hour}:${end.minute}${end.period}`);
- return time.join('-');
- };
- export default dateToPeriod;
Add Comment
Please, Sign In to add comment