From 6eacddf2d0e23666795f1df9cda4c99b836da324 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 18 Aug 2022 12:08:03 +1200 Subject: [PATCH] Use strftime in sqlite instead of new date The javascript date method was messing up the timezones. --- EditSet.tsx | 6 +++--- SetList.tsx | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/EditSet.tsx b/EditSet.tsx index 89eb552..529277e 100644 --- a/EditSet.tsx +++ b/EditSet.tsx @@ -52,12 +52,12 @@ export default function EditSet() { const add = useCallback( async (set: Set) => { - const {name, reps, weight, created, unit} = set; + const {name, reps, weight, unit} = set; const insert = ` INSERT INTO sets(name, reps, weight, created, unit) - VALUES (?,?,?,?,?) + VALUES (?,?,?,strftime('%Y-%m-%dT%H:%M:%S', 'now', 'localtime'),?) `; - await db.executeSql(insert, [name, reps, weight, created, unit]); + await db.executeSql(insert, [name, reps, weight, unit]); notify(); navigation.goBack(); }, diff --git a/SetList.tsx b/SetList.tsx index ee5ec2a..3221f13 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -92,7 +92,6 @@ export default function SetList() { weight: 0, name: '', reps: 0, - created: new Date().toISOString(), id: 0, }; const [repsResult] = await db.executeSql(bestReps, [ @@ -167,12 +166,12 @@ export default function SetList() { const onAdd = useCallback(async () => { const set: Set = { - created: new Date().toISOString(), name: '', id: 0, reps: 0, weight: 0, unit: 'kg', + created: new Date().toISOString(), }; navigation.navigate('EditSet', {set: nextSet || set}); }, [navigation, nextSet]);