Skip to content

Commit

Permalink
Use UTC timezone when building current compatibility date (#558)
Browse files Browse the repository at this point in the history
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 #2881
  • Loading branch information
mrbbot committed Nov 1, 2023
1 parent e66a061 commit eb919b0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/miniflare/src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,16 @@ export const SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
event.respondWith(${BINDING_SERVICE_LOOPBACK}.fetch(request));
})`;

const now = new Date();
const CURRENT_COMPATIBILITY_DATE = [
now.getFullYear(),
(now.getMonth() + 1).toString().padStart(2, "0"),
now.getDate().toString().padStart(2, "0"),
].join("-");

const FALLBACK_COMPATIBILITY_DATE = "2000-01-01";

function getCurrentCompatibilityDate() {
// Get current compatibility date in UTC timezone
const now = new Date().toISOString();
return now.substring(0, now.indexOf("T"));
}

function validateCompatibilityDate(log: Log, compatibilityDate: string) {
if (numericCompare(compatibilityDate, CURRENT_COMPATIBILITY_DATE) > 0) {
if (numericCompare(compatibilityDate, getCurrentCompatibilityDate()) > 0) {
// If this compatibility date is in the future, throw
throw new MiniflareCoreError(
"ERR_FUTURE_COMPATIBILITY_DATE",
Expand Down

0 comments on commit eb919b0

Please sign in to comment.