Created
May 13, 2022 01:36
-
-
Save tofikhidayatxyz/3ac83734fe8d1d8bf6d05b685fe2a550 to your computer and use it in GitHub Desktop.
Countdount Formula
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
| const now = moment().utc(); | |
| const origin = moment(this.dropAt); | |
| const diffDay = origin.diff(now, "days"); | |
| const diffHour = origin.diff(now, "hours"); | |
| const diffMinutes = origin.diff(now, "minutes"); | |
| const diffSeconds = origin.diff(now, "seconds"); | |
| let finalWeek = Math.floor(diffDay / 7); | |
| let finalDay = diffDay - finalWeek * 7; | |
| let finalHours = diffHour - diffDay * 24; | |
| let finalMinutes = diffMinutes - diffHour * 60; | |
| let finalSeconds = diffSeconds - diffMinutes * 60; | |
| // remap and makesure not have 0 | |
| finalWeek = finalWeek < 0 ? 0 : finalWeek; | |
| finalDay = finalDay < 0 ? 0 : finalDay; | |
| finalHours = finalHours < 0 ? 0 : finalHours; | |
| finalMinutes = finalMinutes < 0 ? 0 : finalMinutes; | |
| finalSeconds = finalSeconds < 0 ? 0 : finalSeconds; | |
| // set state | |
| this.week = finalWeek; | |
| this.day = finalDay; | |
| this.hour = finalHours; | |
| this.minute = finalMinutes; | |
| this.second = finalSeconds; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment