Created
March 9, 2018 20:41
-
-
Save uqmessias/db56f2a45bbce131ded455622359926b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment