Skip to content

Commit 9c13c9c

Browse files
masonjameskhoinguyenpham04
authored andcommitted
fix(admin): restore publish date round trip
1 parent df11cd7 commit 9c13c9c

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

packages/admin/src/components/ContentSettingsPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type {
2525
UserListItem,
2626
} from "../lib/api";
2727
import { fetchBylines } from "../lib/api";
28-
import { toDatetimeLocalInputValue } from "../lib/datetime-local.js";
28+
import { fromDatetimeLocalInputValue, toDatetimeLocalInputValue } from "../lib/datetime-local.js";
2929
import { useDebouncedValue } from "../lib/hooks.js";
3030
import { cn, slugify } from "../lib/utils";
3131
import type { CurrentUserInfo } from "./ContentEditor.js";
@@ -410,7 +410,7 @@ export const ContentSettingsPanel = React.memo(function ContentSettingsPanel({
410410

411411
const handlePublishedDateSubmit = () => {
412412
if (publishedDate && onPublishedAtChange) {
413-
onPublishedAtChange(new Date(publishedDate).toISOString());
413+
onPublishedAtChange(fromDatetimeLocalInputValue(publishedDate));
414414
}
415415
};
416416

packages/admin/tests/components/ContentSettingsPanel.test.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,6 @@ describe("ContentSettingsPanel", () => {
148148
it("lets editors update the publish date of published content", async () => {
149149
const onPublishedAtChange = vi.fn();
150150
const previousLocale = i18n.locale;
151-
const NativeDate = Date;
152-
class NonUtcDate extends NativeDate {
153-
constructor(value?: string | number | Date) {
154-
if (value === "2020-06-01T08:45") {
155-
super("2020-06-01T12:45:00.000Z");
156-
} else if (typeof value === "string") {
157-
super(value);
158-
} else if (typeof value === "number") {
159-
super(value);
160-
} else if (value instanceof NativeDate) {
161-
super(value.valueOf());
162-
} else {
163-
super();
164-
}
165-
}
166-
}
167-
vi.stubGlobal("Date", NonUtcDate);
168151
i18n.load("ar", {});
169152
i18n.activate("ar");
170153
try {
@@ -188,10 +171,9 @@ describe("ContentSettingsPanel", () => {
188171
await input.fill("2020-06-01T08:45");
189172
await screen.getByRole("button", { name: "Update publish date" }).click();
190173

191-
expect(onPublishedAtChange).toHaveBeenCalledWith("2020-06-01T12:45:00.000Z");
174+
expect(onPublishedAtChange).toHaveBeenCalledWith("2020-06-01T08:45:00.000Z");
192175
} finally {
193176
i18n.activate(previousLocale);
194-
vi.unstubAllGlobals();
195177
}
196178
});
197179

0 commit comments

Comments
 (0)