memos icon indicating copy to clipboard operation
memos copied to clipboard

UsageHeatMap doesn't account for dailight savings

Open apixandru opened this issue 1 year ago • 0 comments

Describe the bug

todayTimeStamp = 1670216400000 (Mon Dec 05 2022 05:00:00 UTC / Mon Dec 05 2022 00:00:00 ET) todayDay = 7 usedDaysAmount = 79 beginDayTimestemp = 1663390800000 (Sat Sep 17 2022 05:00:00 UTC / Sat Sep 17 2022 01:00:00 ET)

One of my notes had the timestamp 1667086444000

This means that the calculation utils.getDateStampByDate(m.createdTs) - beginDayTimestemp = 3625200000

3625200000/(1000 * 3600 * 24) 41.958333333333336 but there is no 41.95 index, it should be either 41 or 42

the problem appears to be that beginDayTimestamp didn't account for DST on local date, so the adjusted start of date was 1am instead of 12am

if i manually override beginDayTimestamp to 1663387200000 then the calculations are correct and don't crash

Steps to reproduce

I'm not sure why the timestamps can be off sometimes

here is the list of timestamps currently available in the usage heat map

(79) [1663477200000, 1663563600000, 1663650000000, 1663736400000, 1663822800000, 1663909200000, 1663995600000, 1664082000000, 1664168400000, 1664254800000, 1664341200000, 1664427600000, 1664514000000, 1664600400000, 1664686800000, 1664773200000, 1664859600000, 1664946000000, 1665032400000, 1665118800000, 1665205200000, 1665291600000, 1665378000000, 1665464400000, 1665550800000, 1665637200000, 1665723600000, 1665810000000, 1665896400000, 1665982800000, 1666069200000, 1666155600000, 1666242000000, 1666328400000, 1666414800000, 1666501200000, 1666587600000, 1666674000000, 1666760400000, 1666846800000, 1666933200000, 1667019600000, 1667106000000, 1667192400000, 1667278800000, 1667365200000, 1667451600000, 1667538000000, 1667624400000, 1667710800000, 1667797200000, 1667883600000, 1667970000000, 1668056400000, 1668142800000, 1668229200000, 1668315600000, 1668402000000, 1668488400000, 1668574800000, 1668661200000, 1668747600000, 1668834000000, 1668920400000, 1669006800000, 1669093200000, 1669179600000, 1669266000000, 1669352400000, 1669438800000, 1669525200000, 1669611600000, 1669698000000, 1669784400000, 1669870800000, 1669957200000, 1670043600000, 1670130000000, 1670216400000]

Screenshots or additional context

Unhandled Thrown Error! newStat[index] is undefined

UsageHeatMap/<@http://localhost:3001/src/components/UsageHeatMap.tsx:55:9
commitHookEffectListMount@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:16438:34
commitPassiveMountOnFiber@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:17679:44
commitPassiveMountEffects_complete@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:17652:42
commitPassiveMountEffects_begin@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:17642:49
commitPassiveMountEffects@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:17632:42
flushPassiveEffectsImpl@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18985:36
flushPassiveEffects@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18942:22
commitRootImpl@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18911:13
commitRoot@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18772:27
performSyncWorkOnRoot@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18391:21
flushSyncCallbacks@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:8776:30
node_modules/react-dom/cjs/react-dom.development.js/ensureRootIsScheduled/<@http://localhost:3001/node_modules/.vite/deps/chunk-XQXX5H54.js?v=9d2f31c7:18124:21

apixandru avatar Dec 05 '22 16:12 apixandru