diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-10-19 19:53:41 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-10-25 18:46:45 +0200 |
commit | 50222d4dc679dd3c9c8d8ff92a32f5691e607804 (patch) | |
tree | 7e5115f164e4f5e85eb3761f91ff2d02ed3b87b4 /app | |
parent | 048ec287618324e295857be8976be418e4f09703 (diff) | |
download | gitlab-ce-50222d4dc679dd3c9c8d8ff92a32f5691e607804.tar.gz |
Add calculateRemainingMilliseconds() helper function
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/lib/utils/datetime_utility.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js index 1bdf98d0c97..46740308f17 100644 --- a/app/assets/javascripts/lib/utils/datetime_utility.js +++ b/app/assets/javascripts/lib/utils/datetime_utility.js @@ -473,3 +473,15 @@ export const stringifyTime = timeObject => { */ export const abbreviateTime = timeStr => timeStr.split(' ').filter(unitStr => unitStr.charAt(0) !== '0')[0]; + +/** + * Calculates the milliseconds between now and a given date string. + * The result cannot become negative. + * + * @param endDate date string that the time difference is calculated for + * @return {number} number of milliseconds remaining until the given date + */ +export const calculateRemainingMilliseconds = endDate => { + const remainingMilliseconds = new Date(endDate).getTime() - Date.now(); + return Math.max(remainingMilliseconds, 0); +}; |