FIX: New workbooks are created in the users TZ falling back to UTC

This commit is contained in:
Nicolás Hatcher
2025-11-11 06:56:45 +01:00
committed by Nicolás Hatcher Andrés
parent dd78db3d2b
commit ae3fcaf9e9
2 changed files with 13 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import {
uploadFile,
} from "./components/rpc";
import {
createModelWithSafeTimezone,
createNewModel,
deleteModelByUuid,
deleteSelectedModel,
@@ -65,7 +66,7 @@ function App() {
const newModel = loadSelectedModelFromStorage();
if (!newModel) {
setShowWelcomeDialog(true);
const createdModel = new Model("template", "en", "UTC");
const createdModel = createModelWithSafeTimezone();
setModel(createdModel);
} else {
setModel(newModel);

View File

@@ -85,11 +85,21 @@ function getNewName(existingNames: string[]): string {
return "Workbook-Infinity";
}
export function createModelWithSafeTimezone(): Model {
try {
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
return new Model("template", "en", tz);
} catch {
console.warn("Failed to get timezone, defaulting to UTC");
return new Model("template", "en", "UTC");
}
}
export function createNewModel(): Model {
const models = getModelsMetadata();
const name = getNewName(Object.values(models).map((m) => m.name));
const model = new Model(name, "en", "UTC");
const model = createModelWithSafeTimezone();
const uuid = randomUUID();
localStorage.setItem("selected", uuid);
localStorage.setItem(uuid, bytesToBase64(model.toBytes()));