Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: date formating

Brad Barbin94de7fe6e898
diff --git a/packages/form/src/components/DatePicker.tsx b/packages/form/src/components/DatePicker.tsx
index 56a3cf96ee..e68ff771e1 100644
--- a/packages/form/src/components/DatePicker.tsx
+++ b/packages/form/src/components/DatePicker.tsx
@@ -7,7 +7,7 @@ import {
} from "@carbon/react";
import { formatDate } from "@carbon/utils";
import type { CalendarDate } from "@internationalized/date";
-import { getLocalTimeZone, parseDate, toZoned } from "@internationalized/date";
+import { parseDate } from "@internationalized/date";
import { useState } from "react";
import { flushSync } from "react-dom";
import { useField } from "../hooks";
@@ -38,9 +38,7 @@ const DatePicker = ({
);
const handleChange = async (newDate: CalendarDate) => {
- const formattedDate = newDate
- ? toZoned(newDate, getLocalTimeZone()).toAbsoluteString()
- : null;
+ const formattedDate = newDate ? newDate.toString() : null;
flushSync(() => {
setDate(newDate);
});
@@ -57,9 +55,7 @@ const DatePicker = ({
}
};
- const utcValue = date
- ? toZoned(date, getLocalTimeZone()).toAbsoluteString()
- : "";
+ const utcValue = date ? date.toString() : "";
const DatePickerPreview = (
<span className="flex-grow line-clamp-1">{formatDate(utcValue)}</span>
diff --git a/packages/utils/src/date.ts b/packages/utils/src/date.ts
index e5a7d376ab..09ca7a77f9 100644
--- a/packages/utils/src/date.ts
+++ b/packages/utils/src/date.ts
@@ -1,4 +1,9 @@
-import { getLocalTimeZone, parseAbsolute } from "@internationalized/date";
+import {
+ getLocalTimeZone,
+ parseAbsolute,
+ parseDate,
+ toZoned,
+} from "@internationalized/date";
const relativeFormatter = new Intl.RelativeTimeFormat(undefined, {
numeric: "auto",
});
@@ -28,8 +33,13 @@ export function formatDate(
) {
if (!dateString) return "";
try {
+ const _dateString = toZoned(
+ parseDate(dateString),
+ getLocalTimeZone()
+ ).toAbsoluteString();
+
// @ts-expect-error
- const date = parseAbsolute(dateString);
+ const date = parseAbsolute(_dateString);
return new Intl.DateTimeFormat(
undefined,