Add migrations to leading zeros for date settings

Also included the 12-hour formats for leading zeros.
This commit is contained in:
Brandon Presley 2024-02-05 14:24:53 +13:00
parent fe695de487
commit 426c557019
4 changed files with 46 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import { AppDataSource } from "./data-source";
import { settingsRepo } from "./db";
import { ThemeContext } from "./use-theme";
import TimerProgress from "./TimerProgress";
import { MigrationExecutor } from "typeorm";
export const CombinedDefaultTheme = {
...NavigationDefaultTheme,
@ -53,6 +54,7 @@ const App = () => {
(async () => {
if (!AppDataSource.isInitialized)
await AppDataSource.initialize().catch((e) => setError(e.toString()));
const gotSettings = await settingsRepo.findOne({ where: {} });
console.log({ gotSettings });
setAppSettings({

View File

@ -27,9 +27,9 @@ const twelveHours = [
"dd/LL/yyyy, p",
"ccc p",
"p",
"yyyy-MM-d",
"yyyy-MM-d, p",
"yyyy.MM.d",
"yyyy-MM-dd",
"yyyy-MM-dd, p",
"yyyy.MM.dd",
];
const twentyFours = [

View File

@ -39,6 +39,7 @@ import Settings from "./settings";
import Weight from "./weight";
import { settingsDefaultSets1700009253976 } from "./migrations/1700009253976-settings-default-sets";
import { settingsDefaults1700009729468 } from "./migrations/1700009729468-settings-defaults";
import { leadingZeros1707094662099 } from "./migrations/1707094662099-leading-zeros";
export const AppDataSource = new DataSource({
type: "react-native",
@ -84,5 +85,6 @@ export const AppDataSource = new DataSource({
autoConvert1699948105001,
settingsDefaultSets1700009253976,
settingsDefaults1700009729468,
leadingZeros1707094662099,
],
});

View File

@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { settingsRepo } from "../db";
export class leadingZeros1707094662099 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const settings = await settingsRepo.find();
const setting = settings[0];
console.log(`Going from date: ${setting.date}`);
switch (setting.date) {
case "dd/LL/yyyy, k:m":
setting.date = "dd/LL/yyyy, k:mm";
break;
case "ccc k:m":
setting.date = "ccc k:mm";
break;
case "k:m":
setting.date = "k:mm";
break;
case "yyyy-MM-d, p":
setting.date = "yyyy-MM-dd, p";
break;
case "yyyy-MM-d":
setting.date = "yyyy-MM-dd";
break;
case "yyyy-MM-d, k:m":
setting.date = "yyyy-MM-dd, k:mm";
break;
case "yyyy.MM.d":
setting.date = "yyyy.MM.dd";
break;
}
console.log(`To date: ${setting.date}`);
await settingsRepo.save(setting);
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}