Skip to content

Commit 2e509df

Browse files
committed
feat: Add timestamps to backups and exports
This change adds timestamps to backups and exports file names to help distinguish them as you save multiple. fixes: #693
1 parent a4017ba commit 2e509df

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

app/store/settings/export-backup-effects.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { exportData } from '@/store/settings';
55
import { streamToUint8Array } from '@/utils/stream';
66
import 'compression-streams-polyfill';
77
import { toFeedStateDao } from '../feed';
8+
import { DateTimeFormatter, LocalDateTime } from '@js-joda/core';
89

910
export function addExportBackupEffects() {
1011
addEffect(
@@ -42,9 +43,15 @@ export function addExportBackupEffects() {
4243

4344
await writePromise;
4445
await writer.close();
46+
const now = LocalDateTime.now()
47+
.withNano(0)
48+
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
49+
.replaceAll(':', '')
50+
.replaceAll('T', '_')
51+
.replaceAll('-', '');
4552

4653
await fileExportService.exportBytes(
47-
'export.liftlogbackup.gz',
54+
`export.liftlogbackup.${now}.gz`,
4855
await gzippedPromise,
4956
'application/octet-stream',
5057
);

app/store/settings/export-plaintext-effects.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { match } from 'ts-pattern';
1010
import BigNumber from 'bignumber.js';
1111
import { jsonToCSV } from 'react-native-csv';
1212
import { shortFormatWeightUnit } from '@/models/weight';
13+
import { DateTimeFormatter, LocalDateTime } from '@js-joda/core';
1314

1415
export function addExportPlaintextEffects() {
1516
addEffect(
@@ -19,12 +20,18 @@ export function addExportPlaintextEffects() {
1920
{ getState, extra: { progressRepository, fileExportService } },
2021
) => {
2122
const sessions = progressRepository.getOrderedSessions();
23+
const now = LocalDateTime.now()
24+
.withNano(0)
25+
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
26+
.replaceAll(':', '')
27+
.replaceAll('T', '_')
28+
.replaceAll('-', '');
2229
const [fileName, bytes, contentType] = await match(format)
2330
.with(
2431
'CSV',
2532
async () =>
2633
[
27-
'liftlog-export.csv',
34+
`liftlog-export.${now}.csv`,
2835
await exportToCsv(sessions),
2936
'text/csv',
3037
] as const,
@@ -33,7 +40,7 @@ export function addExportPlaintextEffects() {
3340
'JSON',
3441
async () =>
3542
[
36-
'liftlog-export.json',
43+
`liftlog-export.${now}.json`,
3744
await exportToJson(sessions),
3845
'application/json',
3946
] as const,

0 commit comments

Comments
 (0)