nightscout / nightscout-connect

Single entry point for bridging cloud resources containing diabetes data to Nightscout.
GNU Affero General Public License v3.0
31 stars 31 forks source link

Updated Carelink Timezone Handling #15

Closed AndyLow91 closed 11 months ago

AndyLow91 commented 11 months ago

Updated function reassign_zone so it can handle both UTC+ and UTC- timezones.

This was working correctly for timezones that are UTC-x, but UTC+x was returning the following error:

RangeError: Invalid time value at Date.toISOString () at sgs_to_sgv (/opt/app/node_modules/nightscout-connect/lib/sources/minimedcarelink/index.js:54:26) at Array.map () at Object.transformGlucose [as transformer] (/opt/app/node_modules/nightscout-connect/lib/sources/minimedcarelink/index.js:572:10) at transformService (/opt/app/node_modules/nightscout-connect/lib/machines/fetch.js:14:37) at Interpreter._exec (/opt/app/node_modules/xstate/lib/interpreter.js:269:63) at Interpreter.exec (/opt/app/node_modules/xstate/lib/interpreter.js:1026:10) at Interpreter.execute (/opt/app/node_modules/xstate/lib/interpreter.js:387:14) at Interpreter.update (/opt/app/node_modules/xstate/lib/interpreter.js:415:12) at /opt/app/node_modules/xstate/lib/interpreter.js:110:15

Upon investigation, the previously used:

var zoneOffset = lastConduitDateTime.split('-').pop( );

was returning, for example:

'2023-08-06T17:26:47.718+02:00' = 06T17:26:47.718+02:00

bewest commented 11 months ago

Yes! Thanks. BTW, there are some other areas for improvement here. People using 770g pumps have a lot of treatment information, additional devicestatus/iob data, and potentially profile data. Also, all the datetimes in this payload have the same issue with needing the timezone replaced, including the pump clock time uploaded to NS, etc. The clientTimeZone is available, but I think parsing it in a library is more expensive than this approach. Documenting/unit tests are also highly desirable activities.

AndyLow91 commented 11 months ago

I'll do my best to delve in deeper!