Skip to content

Commit 28e75a6

Browse files
authored
Possibly fix Loop time zones not being recognised in profile editor and reports (nightscout#7833)
* * Change profile editor so it works when client uploads profiles where string case doesn't match editor expectations * Re-enable culling down time zone data sent to client * Add a workaround to fix Loop uploading non-ISO compliant time zone identifier
1 parent 0426b01 commit 28e75a6

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

lib/profile/profileeditor.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,20 @@ var init = function init () {
564564
$('#pe_delay_high').val(c_profile.delay_high);
565565
$('#pe_delay_medium').val(c_profile.delay_medium);
566566
$('#pe_delay_low').val(c_profile.delay_low);
567-
timezoneInput.val(c_profile.timezone);
567+
568+
// find the right zone regardless of string case
569+
570+
var foundCase = c_profile.timezone;
571+
572+
if (foundCase != "") {
573+
var lcZone = c_profile.timezone.toLowerCase();
574+
575+
client.ctx.timezones.forEach(function testCase(tz) {
576+
if (tz.toLowerCase() == lcZone) foundCase = tz;
577+
});
578+
}
579+
580+
timezoneInput.val(foundCase);
568581

569582
var index;
570583
[ { prefix:'pe_basal', array:'basal' },
@@ -601,7 +614,15 @@ var init = function init () {
601614
c_profile.delay_high = parseInt($('#pe_delay_high').val());
602615
c_profile.delay_medium = parseInt($('#pe_delay_medium').val());
603616
c_profile.delay_low = parseInt($('#pe_delay_low').val());
604-
c_profile.timezone = timezoneInput.val();
617+
618+
// If the zone in the profile matches the editor profile
619+
// but case is different, preserve case
620+
621+
var zone = timezoneInput.val();
622+
623+
if (c_profile.timezone.toLowerCase() == timezoneInput.val().toLowerCase()) zone = c_profile.timezone;
624+
625+
c_profile.timezone = zone;
605626

606627
var index;
607628
[ { prefix:'pe_basal', array:'basal' },

lib/profilefunctions.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ var moment = ctx.moment;
175175
};
176176

177177
profile.getTimezone = function getTimezone (spec_profile) {
178-
return profile.getCurrentProfile(null, spec_profile)['timezone'];
178+
let rVal = profile.getCurrentProfile(null, spec_profile)['timezone'];
179+
// Work around Loop uploading non-ISO compliant time zone string
180+
if (rVal) rVal.replace('ETC','Etc');
181+
return rVal;
179182
};
180183

181184
profile.hasData = function hasData () {

webpack/webpack.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const webpack = require('webpack');
33
const pluginArray = [];
44
const sourceMapType = 'source-map';
5-
//const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
5+
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
66
const projectRoot = path.resolve(__dirname, '..');
77

88
/*
@@ -56,14 +56,12 @@ pluginArray.push(new webpack.ProvidePlugin({
5656
process: 'process/browser',
5757
}));
5858

59-
/*
6059
// limit Timezone data from Moment
6160

6261
pluginArray.push(new MomentTimezoneDataPlugin({
6362
startYear: 2015,
6463
endYear: 2035,
6564
}));
66-
*/
6765

6866
if (process.env.NODE_ENV === 'development') {
6967
const ESLintPlugin = require('eslint-webpack-plugin');

0 commit comments

Comments
 (0)