From b887ec5f7dbbd5a093081c7782a6007daf0bd0cd Mon Sep 17 00:00:00 2001 From: adam lounds Date: Fri, 25 Oct 2024 14:13:26 +0100 Subject: [PATCH] Use local timezone date in careportal. Fixes nightscout#8304 --- lib/client/careportal.js | 4 ++-- tests/careportal.test.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/client/careportal.js b/lib/client/careportal.js index 514dbf5d650..10f777c8ee1 100644 --- a/lib/client/careportal.js +++ b/lib/client/careportal.js @@ -18,8 +18,8 @@ function init (client, $) { function setDateAndTime (time) { time = time || client.ctx.moment(); - eventTime.val(time.hours() + ":" + time.minutes()); - eventDate.val(time.toISOString().split('T')[0]); + eventDate.val(time.format('YYYY-MM-DD')); + eventTime.val(time.format('HH:mm')); } function mergeDateAndTime () { diff --git a/tests/careportal.test.js b/tests/careportal.test.js index 1da34673535..6284e7b011a 100644 --- a/tests/careportal.test.js +++ b/tests/careportal.test.js @@ -2,6 +2,7 @@ require('should'); var benv = require('benv'); +const moment = require("moment/moment"); var nowData = { sgvs: [ @@ -98,4 +99,17 @@ describe('careportal', function ( ) { }); + it('uses local timezone date, not UTC (8304) ', async () =>{ + const client = window.Nightscout.client; + client.init(); + // sleep(50); + + const fakeNow = moment.parseZone('2024-10-25T23:00:00-05:00'); + client.ctx.moment = () => (fakeNow); + + client.careportal.prepare(); + + $('#eventDateValue').val().should.equal('2024-10-25'); + }); + });