GUACAMOLE-1020: Correct issues with DST not being interpreted correctly.

This commit is contained in:
Virtually Nick
2023-11-04 21:31:54 -04:00
parent e7279f0a8d
commit 1b7c35e189
3 changed files with 43 additions and 19 deletions

View File

@@ -122,7 +122,7 @@ public class DailyRestriction {
* otherwise false. * otherwise false.
*/ */
public boolean appliesNow() { public boolean appliesNow() {
DayOfWeek currentDay = LocalDate.now().getDayOfWeek(); DayOfWeek currentDay = LocalDate.now(ZoneId.of("UTC")).getDayOfWeek();
LocalTime currentTime = LocalTime.now(ZoneId.of("UTC")); LocalTime currentTime = LocalTime.now(ZoneId.of("UTC"));
// Check that we are in the specified time restriction // Check that we are in the specified time restriction

View File

@@ -135,7 +135,7 @@ angular.module('guacRestrict').controller('timeRestrictionFieldController', ['$s
var entry = new TimeRestrictionEntry(); var entry = new TimeRestrictionEntry();
entry.weekDay = '' + currArray[1]; entry.weekDay = '' + currArray[1];
entry.startTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[2].slice(0,2)), parseInt(currArray[2].slice(2)))); entry.startTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[2].slice(0,2)), parseInt(currArray[2].slice(2))));
entry.endTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[3].slice(0,2)), parseInt(currArray[3].slice(2)))) entry.endTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[3].slice(0,2)), parseInt(currArray[3].slice(2))));
restrictions.push(entry); restrictions.push(entry);
} }
} }
@@ -156,15 +156,17 @@ angular.module('guacRestrict').controller('timeRestrictionFieldController', ['$s
* a database. * a database.
*/ */
const storeRestrictions = function storeRestrictions(restrictions) { const storeRestrictions = function storeRestrictions(restrictions) {
// If there are no members of the array, just return an empty string. // If there are no members of the array, just return an empty string.
if (restrictions === null || restrictions.length < 1) if (restrictions === null || restrictions.length < 1)
return ''; return '';
var restrString = ''; let restrString = '';
for (let i = 0; i < restrictions.length; i++) { for (let i = 0; i < restrictions.length; i++) {
// If any of the properties are not defined, skip this one. // If any of the properties are not defined, skip this one.
if (!Object.hasOwn(restrictions[i], 'weekDay') if (!Object.hasOwn(restrictions[i], 'weekDay')
|| restrictions[i].weekDay === null || restrictions[i].weekDay === null
|| restrictions[i].weekDay === ''
|| !Object.hasOwn(restrictions[i], 'startTime') || !Object.hasOwn(restrictions[i], 'startTime')
|| restrictions[i].startTime === null || restrictions[i].startTime === null
|| !(restrictions[i].startTime instanceof Date) || !(restrictions[i].startTime instanceof Date)
@@ -178,34 +180,56 @@ angular.module('guacRestrict').controller('timeRestrictionFieldController', ['$s
restrString += ';'; restrString += ';';
// Add the weekday component of the restriction, insuring it is a string. // Add the weekday component of the restriction, insuring it is a string.
var currString = '' + restrictions[i].weekDay; let currString = '' + restrictions[i].weekDay.toString();
currString += ':'; currString += ':';
// When the field first gets a value, it defaults to a year of 1970
// In order to avoid issues with Daylight Savings Time, we have to
// work around this.
if (restrictions[i].startTime instanceof Date && restrictions[i].startTime.getFullYear() === 1970) {
let startHour = restrictions[i].startTime.getHours();
let startMin = restrictions[i].startTime.getMinutes();
restrictions[i].startTime = new Date();
restrictions[i].startTime.setHours(startHour);
restrictions[i].startTime.setMinutes(startMin);
}
// Retrieve startTime hours component and add it, adding leading zero if required. // Retrieve startTime hours component and add it, adding leading zero if required.
startHours = restrictions[i].startTime.getUTCHours(); let startHours = restrictions[i].startTime.getUTCHours();
if (startHours !== null && startHours < 10) if (startHours !== null && startHours < 10)
startHours = '0' + startHours; currString += '0';
currString += startHours; currString += startHours.toString();
// Retrieve startTime minutes component and add it, adding leading zero if required. // Retrieve startTime minutes component and add it, adding leading zero if required.
startMins = restrictions[i].startTime.getUTCMinutes(); let startMins = restrictions[i].startTime.getUTCMinutes();
if (startMins !== null && startMins < 10) if (startMins !== null && startMins < 10)
startMins = '0' + startMins; currString += '0';
currString += startMins; currString += startMins.toString();
currString += '-'; currString += '-';
// When the field first gets a value, it defaults to a year of 1970
// In order to avoid issues with Daylight Savings Time, we have to
// work around this.
if (restrictions[i].endTime instanceof Date && restrictions[i].endTime.getFullYear() === 1970) {
let endHour = restrictions[i].endTime.getHours();
let endMin = restrictions[i].endTime.getMinutes();
restrictions[i].endTime = new Date();
restrictions[i].endTime.setHours(endHour);
restrictions[i].endTime.setMinutes(endMin);
}
// Retrieve endTime hours component and add it, adding leading zero if required. // Retrieve endTime hours component and add it, adding leading zero if required.
endHours = restrictions[i].endTime.getUTCHours(); let endHours = restrictions[i].endTime.getUTCHours();
if (endHours !== null && endHours < 10) if (endHours !== null && endHours < 10)
endHours = '0' + endHours; currString += '0';
currString += endHours; currString += endHours.toString();
// Retrieve endTime minutes component and add it, adding leading zero if required. // Retrieve endTime minutes component and add it, adding leading zero if required.
endMins = restrictions[i].endTime.getUTCMinutes(); let endMins = restrictions[i].endTime.getUTCMinutes();
if (endMins < 10) if (endMins !== null && endMins < 10)
endMins = '0' + endMins; currString += '0';
currString += endMins; currString += endMins.toString();
// Add the newly-created string to the overall restriction string. // Add the newly-created string to the overall restriction string.
restrString += currString; restrString += currString;

View File

@@ -42,9 +42,9 @@ angular.module('guacRestrict').factory('TimeRestrictionEntry', [
* The numerical representation of the day of the week this restriction * The numerical representation of the day of the week this restriction
* applies to. * applies to.
* *
* @type Number * @type {string}
*/ */
this.weekDay = template.weekDay; this.weekDay = template.weekDay || '';
/** /**
* The hour and minute that this restriction starts, in 24-hour time, * The hour and minute that this restriction starts, in 24-hour time,