From bf8712dbf6b37a2bbfc7a5919d1bdcdaa5eb8387 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 20 Mar 2022 19:21:52 +0100 Subject: [PATCH] Fix dates not being serialized properly in Chromium. --- source/settings/migrations.ts | 3 ++- source/settings/settings.ts | 11 ++++++++--- tests/snapshots/tests/migrations.test.ts.md | 2 +- tests/snapshots/tests/migrations.test.ts.snap | Bin 508 -> 523 bytes 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source/settings/migrations.ts b/source/settings/migrations.ts index 9b55902..c47b6bc 100644 --- a/source/settings/migrations.ts +++ b/source/settings/migrations.ts @@ -37,7 +37,8 @@ export function serializeQueue(queue: Queue.Item[]): Record { for (const item of queue) { const key = `qi${item.id}`; - serialized[key] = item; + serialized[key] = {...item}; + serialized[key].added = item.added.toISOString(); } return serialized; diff --git a/source/settings/settings.ts b/source/settings/settings.ts index dd3f983..2f208cf 100644 --- a/source/settings/settings.ts +++ b/source/settings/settings.ts @@ -47,9 +47,14 @@ export class Settings { }; this.queue.push(item); - const sync: Record = {}; - sync[`qi${id}`] = item; - await browser.storage.sync.set(sync); + await browser.storage.sync.set({ + [`qi${id}`]: { + added: item.added.toISOString(), + id, + text, + url, + }, + }); } public newQueueItemId(): number { diff --git a/tests/snapshots/tests/migrations.test.ts.md b/tests/snapshots/tests/migrations.test.ts.md index 861c8f0..69c9ee7 100644 --- a/tests/snapshots/tests/migrations.test.ts.md +++ b/tests/snapshots/tests/migrations.test.ts.md @@ -32,7 +32,7 @@ Generated by [AVA](https://avajs.dev). { qi1: { - added: Date 2022-03-02 16:00:00 UTC {}, + added: '2022-03-02T16:00:00.000Z', id: 1, text: 'Sample', url: 'https://example.org', diff --git a/tests/snapshots/tests/migrations.test.ts.snap b/tests/snapshots/tests/migrations.test.ts.snap index 2131bf4569ceb586d894d89ad7103575a07911ba..a673a361874dd3cdc99f214d0daa702ad73bcebb 100644 GIT binary patch literal 523 zcmV+m0`&bsRzV^M=xG&sdJ2e^u1&?P& zdO=!zEgy>r00000000BkQ!!85P!N7+$Dt~sNd!_sEJi||8uMZhR8bcs76yc>Fc7vE zd`%uTv9X^~Qgvy%_D?htEd2wWyLIi%-$3ftUL0PMIxUSlRI24qcW2+z-F@G^4=)>j zaQZ5K*GDClkDV1yC~+X0kx(*d$97AEVb>0YYRR}Q!nhTv_-)@CWYwW*vN<+*-~pH} z*=K|U!Xo5LkUwmk;i&=`xy53U!2$z=!6Sf(5|_YaV3okUkQD|6I%w!mbC(#!)Ps&K z?o^zeK`HBsPJSeOCfpFdXG2gW5W;d$s~iW<^O-5fyXPflS+=^$Sd=b?|8 z6f=o@?Ju^J3gha=26oa^Cy1I19#gtmEWxtNUAN3P%iKMxY*#s_*WsL>q*LVfghDXy z9GU=q(Lg^K$zrEeXvtPHk|phXL_4leXl6KMxBjeGmWy9YbAOj>HH@V2`XWE;eMjvjCj()4-zg(*!?`N7{ z^fY^wN%o$Sb@jZ~ZWM{`fV`nsC=?hxOu3r}c&-mw0ojD`o^Vb0GV4YA#{T1r=8u;X Ny&t{5sPG~M003(B@2mg- literal 508 zcmVq+$NDZK}3h;rZn0Qo@P&cFU<4qd#IIm7uu5Pa$O?l36&m_z;1HvjX3(+4or*Kt zZe{(Z%D;qL!UN$c+tPT|GMBb=pxe?Co`+thsUf}8%>iU?atd2Y2l;ieANrU{F_XyG z{%Av~FrJ&9##Wl@1W}#A7^R!V5`1&H>z4UUnY$a6pL3kk?{Lny(pTh`ghDX?IrIYb zMGgI+Ba59zQ7#g^vwON-w`!F4~(DIy@s>5^f0h{qBwRnfGQ_GmoC;wbIM$6j@g@VJ$|H yIBL`S;uQ)7216;U!vOQT$O_0NgbTtS!d<^qKC(|trQcm!^qv8Kpooq<1polgGwxIX