Skip to content

Commit

Permalink
Possibly fix Loop time zones not being recognised in profile editor a…
Browse files Browse the repository at this point in the history
…nd 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
  • Loading branch information
sulkaharo committed Jan 24, 2023
1 parent 0426b01 commit 28e75a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
25 changes: 23 additions & 2 deletions lib/profile/profileeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,20 @@ var init = function init () {
$('#pe_delay_high').val(c_profile.delay_high);
$('#pe_delay_medium').val(c_profile.delay_medium);
$('#pe_delay_low').val(c_profile.delay_low);
timezoneInput.val(c_profile.timezone);

// find the right zone regardless of string case

var foundCase = c_profile.timezone;

if (foundCase != "") {
var lcZone = c_profile.timezone.toLowerCase();

client.ctx.timezones.forEach(function testCase(tz) {
if (tz.toLowerCase() == lcZone) foundCase = tz;
});
}

timezoneInput.val(foundCase);

var index;
[ { prefix:'pe_basal', array:'basal' },
Expand Down Expand Up @@ -601,7 +614,15 @@ var init = function init () {
c_profile.delay_high = parseInt($('#pe_delay_high').val());
c_profile.delay_medium = parseInt($('#pe_delay_medium').val());
c_profile.delay_low = parseInt($('#pe_delay_low').val());
c_profile.timezone = timezoneInput.val();

// If the zone in the profile matches the editor profile
// but case is different, preserve case

var zone = timezoneInput.val();

if (c_profile.timezone.toLowerCase() == timezoneInput.val().toLowerCase()) zone = c_profile.timezone;

c_profile.timezone = zone;

var index;
[ { prefix:'pe_basal', array:'basal' },
Expand Down
5 changes: 4 additions & 1 deletion lib/profilefunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ var moment = ctx.moment;
};

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

profile.hasData = function hasData () {
Expand Down
4 changes: 1 addition & 3 deletions webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const webpack = require('webpack');
const pluginArray = [];
const sourceMapType = 'source-map';
//const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');
const projectRoot = path.resolve(__dirname, '..');

/*
Expand Down Expand Up @@ -56,14 +56,12 @@ pluginArray.push(new webpack.ProvidePlugin({
process: 'process/browser',
}));

/*
// limit Timezone data from Moment

pluginArray.push(new MomentTimezoneDataPlugin({
startYear: 2015,
endYear: 2035,
}));
*/

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

0 comments on commit 28e75a6

Please sign in to comment.