Skip to content

Commit 35d37da

Browse files
committed
remove Temporal and only use date-fns
1 parent 590a16d commit 35d37da

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
"@headlessui/react": "^2.2.0",
2626
"@heroicons/react": "^2.2.0",
2727
"@icons-pack/react-simple-icons": "^12.3.0",
28-
"@js-temporal/polyfill": "^0.4.4",
2928
"@jsdevtools/rehype-url-inspector": "^2.0.2",
3029
"@octokit/core": "^6.1.4",
3130
"@shikijs/transformers": "^3.2.1",
3231
"@sindresorhus/slugify": "^2.2.1",
3332
"@wpengine/atlas-next": "^2.0.1",
3433
"date-fns": "^4.1.0",
34+
"date-fns-tz": "^3.2.0",
3535
"downshift": "^9.0.9",
3636
"feed": "^4.2.2",
3737
"graphql": "^16.10.0",

src/lib/feed.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { env } from "node:process";
22
import { URL } from "node:url";
33
import { gql } from "@apollo/client";
4-
import { Temporal } from "@js-temporal/polyfill";
4+
import { format } from "date-fns-tz";
55
import { Feed } from "feed";
66

77
const SITE_URL = env.NEXT_PUBLIC_SITE_URL;
@@ -56,9 +56,9 @@ export function createFeed({ feed_data, last_modified }) {
5656
language: "en",
5757
image: new URL("/favicon-192x192.png", SITE_URL).href,
5858
favicon: new URL("/favicon-32x32.png", SITE_URL).href,
59-
copyright: Temporal.Now.plainDateISO(
60-
feed_data.generalSettings.timezone,
61-
).year.toString(),
59+
copyright: format(new Date(), "yyyy", {
60+
timeZone: feed_data.generalSettings.timezone,
61+
}),
6262
updated: new Date(last_modified.toString()),
6363
feedLinks: {
6464
json: new URL("/api/feeds/feed.json", SITE_URL).href,

src/pages/api/feeds/[feed-type].js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHash } from "node:crypto";
22
import { getApolloClient } from "@faustwp/core/dist/mjs/client";
3-
import { Temporal } from "@js-temporal/polyfill";
3+
import { parseISO, compareAsc } from "date-fns"; // Replaced Temporal with date-fns
44
import { StatusCodes, getReasonPhrase } from "http-status-codes";
55
import { FEED_QUERY, createFeed } from "@/lib/feed";
66

@@ -18,12 +18,9 @@ export default async function HandleFeeds(req, res) {
1818
query: FEED_QUERY,
1919
});
2020

21-
const last_modified = Temporal.PlainDateTime.from(
21+
const last_modified = parseISO(
2222
feed_data.last_modified.nodes[0].modifiedGmt,
23-
{
24-
overflow: "constrain",
25-
},
26-
);
23+
); // Replaced Temporal.PlainDateTime.from
2724

2825
// Create feed
2926
const feed = createFeed({ feed_data, last_modified });
@@ -75,14 +72,14 @@ export default async function HandleFeeds(req, res) {
7572
);
7673
res.setHeader("Content-Type", resp.content_type);
7774
res.setHeader("ETag", etag_for_body);
78-
res.setHeader("Last-Modified", last_modified.toString());
75+
res.setHeader("Last-Modified", last_modified.toUTCString()); // Adjusted to use Date's toUTCString()
7976

8077
if (
8178
// Checks if the `if_none_match` header matches current response' etag
8279
if_none_match === etag_for_body ||
8380
// Checks `if_modified_since` is after `last_modified`
8481
(if_modified_since &&
85-
Temporal.PlainDateTime.compare(last_modified, if_modified_since) < 0)
82+
compareAsc(last_modified, new Date(if_modified_since)) < 0) // Replaced Temporal.PlainDateTime.compare
8683
) {
8784
res.status(StatusCodes.NOT_MODIFIED);
8885
res.end();

0 commit comments

Comments
 (0)