Created
April 28, 2021 13:27
-
-
Save vladcorn/04227d03f4a3dc328472de5eb7ffd533 to your computer and use it in GitHub Desktop.
This file contains 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
const formatDurationPolls = ( | |
createdAt: Date, | |
duration: number, | |
timeOfEdit: Date = new Date() | |
) => { | |
const ends = moment(new Date(createdAt).getTime() + duration * 60000); | |
const days = moment(timeOfEdit).diff(ends, 'days') * -1; | |
const hours = moment(timeOfEdit).diff(ends, 'hours') * -1 - days * 24; | |
const minutes = | |
moment(timeOfEdit).diff(ends, 'minutes') * -1 - | |
days * 24 * 60 - | |
hours * 60; | |
return { days, hours, minutes }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment