From 50b8fe2e988ec43826810905e737c037b65e3f17 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 13 Dec 2023 17:24:15 +0100 Subject: [PATCH] MOBILE-3947 ion-datetime: Fix timestamp supplied to datetime ion-datetime no longer uses time zone, it's always UTC now so we had to adapt the initial value supplied. No change needed when reading the value because moment automatically uses the user timezone if the value doesn't specify a timezone. --- src/core/services/utils/time.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts index fb7865e04..24cb2857c 100644 --- a/src/core/services/utils/time.ts +++ b/src/core/services/utils/time.ts @@ -208,7 +208,11 @@ export class CoreTimeUtilsProvider { * @returns Formatted time. */ toDatetimeFormat(timestamp?: number): string { - return moment(timestamp || Date.now()).toISOString(); + const isoString = moment(timestamp || Date.now()).toISOString(true); + + // Remove milliseconds and timezone for consistency with the values used by ion-datetime. + // ion-datetime no longer uses timezone, it always uses UTC. + return isoString.substring(0, isoString.indexOf('.')); } /**