From a47bbf7ce093a46ce83cd66da5d9ce3150324860 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 3 Nov 2020 20:34:32 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-5-stable-ee --- app/assets/javascripts/lib/utils/datetime_utility.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/assets/javascripts/lib') diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js index 6e78dc87c02..753245147d2 100644 --- a/app/assets/javascripts/lib/utils/datetime_utility.js +++ b/app/assets/javascripts/lib/utils/datetime_utility.js @@ -657,6 +657,24 @@ export const secondsToMilliseconds = seconds => seconds * 1000; */ export const secondsToDays = seconds => Math.round(seconds / 86400); +/** + * Converts a numeric utc offset in seconds to +/- hours + * ie -32400 => -9 hours + * ie -12600 => -3.5 hours + * + * @param {Number} offset UTC offset in seconds as a integer + * + * @return {String} the + or - offset in hours + */ +export const secondsToHours = offset => { + const parsed = parseInt(offset, 10); + if (Number.isNaN(parsed) || parsed === 0) { + return `0`; + } + const num = offset / 3600; + return parseInt(num, 10) !== num ? num.toFixed(1) : num; +}; + /** * Returns the date n days after the date provided * -- cgit v1.2.1