Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daytoday reports are always in the profile's time zone #7836

Closed
wants to merge 6 commits into from

Conversation

bewest
Copy link
Member

@bewest bewest commented Jan 15, 2023

Midnight for the profile should always be at the start of the day (midnight) for the chart. There's logic for this in lib/report/reportclient.js, but believe it needs to be here as well.

Midnight for the profile should always be at the start of the
day (midnight) for the chart.
@bewest bewest mentioned this pull request Jan 15, 2023
This more closely mirrors logic in loopalyzer, as well as the intent from the
surrounding code in reportclient.js.
@marionbarker
Copy link

Been a little busy with Loop 3 docs. I appreciate this and I will try it soon.

@bewest
Copy link
Member Author

bewest commented Jan 18, 2023

Thanks for the updates!
#4901 (comment)

I expected there to be a kind of "off by one" error, so the right column second row actually makes sense to me. This is progress.

As for the date being wrong, can you be a bit more explicit. There seems to be a date rollover effect with respect to midnight. Did you pull up these reports at a time when the -2, +3 would have resulting in rolling over midnight? Is the date correct in the other timezone for one of those cases? We're close. If possible, I'd like to peek at your NS instance to poke at it, we can discuss that in a private channel.

To illustrate the difference, I used chrome "sensors" feature to change my timezone to one that spans the dateline.

    > moment.tz('2023-01-19', 'America/Los_Angeles').endOf('day').format( )
    '2023-01-19T23:59:59-08:00'
    > moment.tz(moment('2023-01-19'), 'America/Los_Angeles').endOf('day').format( )
    '2023-01-18T23:59:59-08:00'

The old code uses a string replacement, which is equivalent to the first
test.  This causes the dates on the reports to be off by one, as well as
risks the data wrapping around the dateline so it can't be seen.  For example,
replacing "23:59:59" with "00:00:00" in the first example doesn't correctly
wrap around the dateline.

The patch introduces a way to parse the dates requested in the browser's
time zone, and then translates them to the profile's timezone.  The
difference is shown in the second example above.  With this change, the
correct date label should be rendered, and the data should start at
midnight without wrapping around the dateline.
This fixes the label on the days in the daytoday charts.  Passing a moment
object that is already zoned prevents toLocaleDateString from reinterpreting
the zone information when the date is already relative to the profile.

This also ensures that the datefilter is adjusted to the profile's zone rather
than truncating the time to the end or beginning of the day.  This should
prevent incorrectly wrapping arounnd the dateline.
@bewest
Copy link
Member Author

bewest commented Jan 18, 2023

Tests do not pass, but I suspect it's something with the tests themselves. This is worth trying, as it should handle both remaining issues:

  • title of the day is incorrect (always the previous day?)
  • midnight wrapping around to next day when crossing the datetime line.

@sulkaharo
Copy link
Member

Yea if you've changed the date logic, it's likely the report outputs different values. Check reports.test.js starting line 273

marionbarker added a commit to marionbarker/cgm-remote-monitor that referenced this pull request Jan 19, 2023
Try latest from nightscout#7836 up through commit 8764b84
marionbarker added a commit to marionbarker/cgm-remote-monitor that referenced this pull request Jan 19, 2023
marionbarker added a commit to marionbarker/cgm-remote-monitor that referenced this pull request Jan 19, 2023
Additional change to match nightscout#7836
@marionbarker
Copy link

I tried the changes through 8764b84 alone and with 7833 patched into master. Did not fix the problem.
I'm installing straight dev now. When I have time, I'll try the patches for dev.

@bewest
Copy link
Member Author

bewest commented Jan 20, 2023

Strange tests... on my machine, many tests fail (careportal, hashauth) because loading the html into self.$('body').html(indexHTML) in tests/fixtures/headless.js takes more than 60 seconds allowed by the test. If I adjust it to 65 seconds some tests work, but I still get an error in "hashauth should store hash and the remove authentication:"`[

not ok 298 hashauth should store hash and the remove authentication
  Cannot read property 'should' of null
  TypeError: Cannot read property 'should' of null
      at Context.<anonymous> (tests/hashauth.test.js:126:49)
      at benv.setup.url (tests/fixtures/headless.js:174:7)
      at Object.module.exports.setup (node_modules/benv/index.js:24:56)
      at Function.init [as setup] (tests/fixtures/headless.js:24:10)
      at Context.<anonymous> (tests/hashauth.test.js:28:14)
      at processImmediate (internal/timers.js:464:21)

This is puzzling as these changes don't interact with any of that code.

Notably, this is different from the failures seen in github actions, which fails the report test, which does not occur on my machine. In theory just widening the date range for the query should in theory should allow the test to pass, but given the other oddities here, it's a little odd.

@bewest
Copy link
Member Author

bewest commented Jan 24, 2023

closing in favor of #7857

@bewest bewest closed this Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants