From 3f11b54f41a8824dcfd3fd5a1de371fd4b2b19e9 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 26 Feb 2025 14:07:27 +0800 Subject: [PATCH] Refactor date handling in abp.js and add normalizeString function for date formatting --- npm/packs/core/src/abp.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/npm/packs/core/src/abp.js b/npm/packs/core/src/abp.js index 45b8ac3ba3..35b186d0f0 100644 --- a/npm/packs/core/src/abp.js +++ b/npm/packs/core/src/abp.js @@ -765,7 +765,7 @@ var abp = abp || {}; }; var toUtc = function (date) { - return Date.UTC( + return new Date(Date.UTC( date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), @@ -773,7 +773,7 @@ var abp = abp || {}; date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds() - ); + )); }; abp.clock.now = function () { @@ -799,6 +799,25 @@ var abp = abp || {}; } }; + abp.clock.normalizeString = function (dateString) { + var date = abp.clock.normalize(new Date(dateString)); + + var kind = abp.clock.kind; + + if(kind === 'Local' || kind === 'Unspecified'){ + return date.getFullYear() + "-" + + String(date.getMonth() + 1).padStart(2, "0") + "-" + + String(date.getDate()).padStart(2, "0") + "T" + + String(date.getHours()).padStart(2, "0") + ":" + + String(date.getMinutes()).padStart(2, "0") + ":" + + String(date.getSeconds()).padStart(2, "0") + ".000"; + } + + if(kind === 'Utc'){ + return date.toISOString(); + } + } + /* FEATURES *************************************************/ abp.features = abp.features || {};