+43
-10
src/routes/rnfgrertt/borgle.lazy.tsx
+43
-10
src/routes/rnfgrertt/borgle.lazy.tsx
···
3
3
import { QtContext } from "@/providers/qtprovider";
4
4
import { Check, Loader2, Clipboard } from "lucide-react";
5
5
import { generateTid, tidToTime } from "@/lib/tid";
6
+
import { timeAgo } from "@/lib/utils";
6
7
7
8
import { WORD_LIST, ACCEPTED_WORDS } from "@/lib/borgle-lists";
8
9
import { StateUpdater } from "preact/hooks";
···
87
88
88
89
// Get word and puzzle number based on the current date
89
90
function getTodaysWordData(): WordData {
90
-
const today = new Date();
91
-
const startDate = new Date("2025-06-10"); // Reference start date
91
+
const now = new Date();
92
+
const today = new Date(
93
+
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()),
94
+
);
95
+
const startDate = new Date("2025-06-10T00:00:00Z"); // Reference start date in UTC
92
96
const daysSinceStart = Math.floor(
93
97
(today.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24),
94
98
);
···
100
104
return {
101
105
word: WORD_LIST[index],
102
106
puzzleNumber: daysSinceStart + 1, // Start from puzzle #1
103
-
date: today.toLocaleDateString(),
107
+
date: today.toISOString().split("T")[0], // Use UTC date
104
108
};
105
109
}
106
110
···
135
139
const [hasSubmittedToday, setHasSubmittedToday] = useState<boolean>(false);
136
140
const [submissionRecord, setSubmissionRecord] = useState<string>("");
137
141
const [submissionError, setSubmissionError] = useState<string>("");
142
+
const [nextPuzzleTime, setNextPuzzleTime] = useState<string>("");
138
143
139
144
// Initialize game
140
145
useEffect(() => {
···
143
148
}
144
149
}, [checkingSubmission, todaysSubmission]);
145
150
151
+
// Update countdown timer
152
+
useEffect(() => {
153
+
const updateCountdown = () => {
154
+
const now = new Date();
155
+
const nextMidnightUTC = new Date();
156
+
nextMidnightUTC.setUTCDate(nextMidnightUTC.getUTCDate() + 1);
157
+
nextMidnightUTC.setUTCHours(0, 0, 0, 0); // Set to UTC midnight
158
+
159
+
setNextPuzzleTime(
160
+
timeAgo(nextMidnightUTC, { future: true, useShortLabels: true }),
161
+
);
162
+
};
163
+
164
+
updateCountdown(); // Initial update
165
+
const interval = setInterval(updateCountdown, 60000); // Update every minute
166
+
167
+
return () => clearInterval(interval);
168
+
}, []);
169
+
146
170
// Submit playthrough when game ends
147
171
useEffect(() => {
148
172
const submitPlaythrough = async () => {
···
152
176
153
177
try {
154
178
setHasSubmittedToday(true);
155
-
// Check if today's submission already exists
156
-
const today = new Date().toISOString().split("T")[0];
179
+
// Check if today's submission already exists (using UTC date)
180
+
const now = new Date();
181
+
const todayUTC = new Date(
182
+
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()),
183
+
);
184
+
const today = todayUTC.toISOString().split("T")[0];
157
185
const response = await qt.client.rpc.get(
158
186
"com.atproto.repo.listRecords",
159
187
{
···
255
283
try {
256
284
console.log("Checking submission");
257
285
const wordData = getTodaysWordData();
258
-
const today = new Date().toISOString().split("T")[0]; // YYYY-MM-DD format
286
+
const now = new Date();
287
+
const todayUTC = new Date(
288
+
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()),
289
+
);
290
+
const today = todayUTC.toISOString().split("T")[0]; // YYYY-MM-DD format in UTC
259
291
260
292
const response = await qt.client.rpc.get("com.atproto.repo.listRecords", {
261
293
params: {
···
617
649
};
618
650
619
651
const generateCurrentGameState = (): string => {
620
-
let state = `Borgle Puzzle #${puzzleNumber} (${todaysDate})\n`;
652
+
let state = `Borgle Puzzle #${puzzleNumber}\n`;
621
653
622
654
for (let res in evaluations) {
623
655
const evalRow = evaluations[res];
···
718
750
<h1 className="text-4xl font-bold tracking-wide">BORGLE</h1>
719
751
{puzzleNumber > 0 && (
720
752
<div className="text-sm text-muted-foreground mt-1">
721
-
Puzzle #{puzzleNumber} • {todaysDate}
753
+
Puzzle #{puzzleNumber} • {todaysDate} Zulu time
722
754
</div>
723
755
)}
724
756
</div>
···
739
771
740
772
<div className="text-center">
741
773
<div className="text-sm text-gray-500 mb-4">
742
-
Come back tomorrow for the next puzzle!
774
+
Come back after midnight UTC ({nextPuzzleTime}) for the next
775
+
puzzle!
743
776
</div>
744
777
<button
745
778
onClick={() => {
···
827
860
/>
828
861
</div>
829
862
<div className="text-xs text-gray-500 mt-2">
830
-
Daily word changes at midnight
863
+
Daily puzzle changes at midnight UTC ({nextPuzzleTime})
831
864
</div>
832
865
</div>
833
866
) : (