Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit f0f1634

Browse files
authored
Use UTC timezone when building current compatibility date (#558)
When a user specifies a compatibility date, Miniflare compares it against the current date to make sure it's not in the future. Previously, we used the system timezone when getting the current date. Wrangler's default compatibility date is the current date in the _UTC_ timezone. This meant Miniflare occasionally thought Wrangler's compatibility date was in the future. This change updates Miniflare to always use UTC when getting the current date. Closes cloudflare/workers-sdk#2881
1 parent 32bdee3 commit f0f1634

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/tre/src/plugins/core/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,16 @@ export const SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
243243
event.respondWith(${BINDING_SERVICE_LOOPBACK}.fetch(request));
244244
})`;
245245

246-
const now = new Date();
247-
const CURRENT_COMPATIBILITY_DATE = [
248-
now.getFullYear(),
249-
(now.getMonth() + 1).toString().padStart(2, "0"),
250-
now.getDate().toString().padStart(2, "0"),
251-
].join("-");
252-
253246
const FALLBACK_COMPATIBILITY_DATE = "2000-01-01";
254247

248+
function getCurrentCompatibilityDate() {
249+
// Get current compatibility date in UTC timezone
250+
const now = new Date().toISOString();
251+
return now.substring(0, now.indexOf("T"));
252+
}
253+
255254
function validateCompatibilityDate(log: Log, compatibilityDate: string) {
256-
if (numericCompare(compatibilityDate, CURRENT_COMPATIBILITY_DATE) > 0) {
255+
if (numericCompare(compatibilityDate, getCurrentCompatibilityDate()) > 0) {
257256
// If this compatibility date is in the future, throw
258257
throw new MiniflareCoreError(
259258
"ERR_FUTURE_COMPATIBILITY_DATE",

0 commit comments

Comments
 (0)