From 43ff05501799c43e5f266b2276b96472dcb1530e Mon Sep 17 00:00:00 2001 From: Abdallah Alhalees Date: Thu, 12 Dec 2024 14:51:40 +0100 Subject: [PATCH] refactor: Use custom function to format month instead of date-fns function --- src/internal/utils/date-time/format-date-iso.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/internal/utils/date-time/format-date-iso.ts b/src/internal/utils/date-time/format-date-iso.ts index 5a4f0d93c4..960b8d9ddf 100644 --- a/src/internal/utils/date-time/format-date-iso.ts +++ b/src/internal/utils/date-time/format-date-iso.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { format, parseISO } from 'date-fns'; +import { parseISO } from 'date-fns'; import { formatTimeOffsetISO } from './format-time-offset'; @@ -19,7 +19,11 @@ export default function ({ }) { const formattedOffset = hideTimeOffset || isDateOnly || isMonthOnly ? '' : formatTimeOffsetISO(isoDate, timeOffset); if (isMonthOnly) { - return format(parseISO(isoDate), 'yyyy-MM'); + const date = parseISO(isoDate); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + return `${year}-${month}`; } + return isoDate + formattedOffset; }