Skip to content

Instantly share code, notes, and snippets.

@vladcorn
Created April 28, 2021 13:27
Show Gist options
  • Save vladcorn/04227d03f4a3dc328472de5eb7ffd533 to your computer and use it in GitHub Desktop.
Save vladcorn/04227d03f4a3dc328472de5eb7ffd533 to your computer and use it in GitHub Desktop.
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