summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js')
-rw-r--r--app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js b/app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js
index 396c1703c1e..4e7086e62c5 100644
--- a/app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js
+++ b/app/assets/javascripts/lib/utils/datetime/date_calculation_utility.js
@@ -1,5 +1,5 @@
import { isNumber } from 'lodash';
-import { __, n__ } from '../../../locale';
+import { __, n__ } from '~/locale';
import { getDayName, parseSeconds } from './date_format_utility';
const DAYS_IN_WEEK = 7;
@@ -189,13 +189,21 @@ export const getDateInFuture = (date, daysInFuture) =>
*/
export const isValidDate = (date) => date instanceof Date && !Number.isNaN(date.getTime());
-/*
+/**
* Appending T00:00:00 makes JS assume local time and prevents it from shifting the date
* to match the user's time zone. We want to display the date in server time for now, to
* be consistent with the "edit issue -> due date" UI.
+ *
+ * @param {String} date Date without time, e.g. `2022-03-22`
+ * @return {Date} new Date object
*/
-
export const newDateAsLocaleTime = (date) => {
+ if (!date || typeof date !== 'string') {
+ return null;
+ }
+ if (date.includes('T')) {
+ return new Date(date);
+ }
const suffix = 'T00:00:00';
return new Date(`${date}${suffix}`);
};