mlool / workday-calendar-extension

MIT License
58 stars 22 forks source link

24-hour time broken: period.toLowerCase() being called when period is null #16

Closed david-mcpherson closed 5 months ago

david-mcpherson commented 5 months ago

Sections cannot be added for 24-hour clock users.

Here's the console error: image

The convertTo24HourFormat function extracts timePart and period from the given time. 12-hour times have a period like 'a.m.' or 'p.m.'. But 24-hour times have a period of null.

The function calls period.toLowerCase(), even if the period is null.

Current code: if (period.toLowerCase() === 'p.m.' && hours !== 12) { hours += 12; } else if (period.toLowerCase() === 'a.m.' && hours === 12) { hours = 0; }

Proposed fix: if (period && period.toLowerCase() === 'p.m.' && hours !== 12) { hours += 12; } else if (period && period.toLowerCase() === 'a.m.' && hours === 12) { hours = 0; }

Vaten0x commented 5 months ago

I don't think this issue is there any more in the develop branch, it has been fixed

david-mcpherson commented 5 months ago

I don't think this issue is there any more in the develop branch, it has been fixed

It's still reproducible as of 5577fba8b2787e80e4130944ebfed90e47525fec. But it is still fixed by prepending the if condition with a guard to check that period is defined.

david-mcpherson commented 5 months ago

PR: https://github.com/mlool/workday-calendar-extension/pull/25