Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling more formats to input hours and minutes in preferences #1020

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<!--- Begin changes - Do not remove -->


<!--- End changes - Do not remove -->

Who built 3.0.1:
Expand Down
4 changes: 2 additions & 2 deletions src/preferences.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When one inputs something wrong, the html message asks to follow the requested format, but that is not explicit.
Is there a way to customize that html message?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, consider if it's possible to implement extra tests for this behavior to ensure it's always working.

Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
</div>
<div class="flex-box">
<p data-i18n="$Preferences.hoursPerDay">Hours per day</p>
<input data-i18n="[placeholder]$Preferences.hours-per-day;[oninvalid]$Generic.hours-on-invalid" type="text" name="hours-per-day" id="hours-per-day" maxlength=5 pattern="^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" value="08:00" size=5 required oninput="this.setCustomValidity('');this.reportValidity()" onblur="this.value = this.checkValidity() ? this.value : '08:00';this.setCustomValidity('')">
<input data-i18n="[placeholder]$Preferences.hours-per-day;[oninvalid]$Generic.hours-on-invalid" type="text" name="hours-per-day" id="hours-per-day" maxlength=5 pattern="^((0|1)?[0-9]|2[0-3])(\.[0-9][0-9]?|:[0-5][0-9])?$" value="08:00" size=5 required oninput="this.setCustomValidity('');this.reportValidity()" onblur="this.value = this.checkValidity() ? this.value : '08:00';this.setCustomValidity('')">
</div>
<div class="flex-box">
<p><i class="fas fa-utensils"></i><span data-i18n="$Preferences.enablePrefillBreakTime">Enable prefilling of break time</span></p>
<label class="switch"><input type="checkbox" id='enable-prefill-break-time' name="enable-prefill-break-time"><span class="slider round"></span></label>
</div>
<div class="flex-box">
<p data-i18n="$Preferences.breakTimeInterval">Break time interval</p>
<input data-i18n="[placeholder]$Preferences.hours-per-day" type="text" name="break-time-interval" id="break-time-interval" maxlength=5 pattern="^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" value="00:30" size=5 required oninput="this.reportValidity()" onblur="this.value = this.checkValidity() ? this.value : '00:30'">
<input data-i18n="[placeholder]$Preferences.hours-per-day" type="text" name="break-time-interval" id="break-time-interval" maxlength=5 pattern="^((0|1)?[0-9]|2[0-3])(\.[0-9][0-9]?|:[0-5][0-9])?$" value="00:30" size=5 required oninput="this.reportValidity()" onblur="this.value = this.checkValidity() ? this.value : '00:30'">
</div>

</section>
Expand Down
41 changes: 40 additions & 1 deletion src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,46 @@ function renderPreferencesWindow()
/* istanbul ignore else */
if (this.checkValidity() === true)
{
changeValue(this.name, this.value);
let entry = this.value;
araujoarthur0 marked this conversation as resolved.
Show resolved Hide resolved
const colonIdx = entry.indexOf(':');
const periodIdx = entry.indexOf('.');
if (colonIdx !== -1)
{
// contains :
araujoarthur0 marked this conversation as resolved.
Show resolved Hide resolved
/* istanbul ignore else */
araujoarthur0 marked this conversation as resolved.
Show resolved Hide resolved
if (colonIdx <= 1)
{
// only 1 digit before :
entry = '0'.concat(entry);
}
}
else if (periodIdx !== -1)
{
// contains .
let n = parseFloat('0'.concat(entry.substring(periodIdx)));
araujoarthur0 marked this conversation as resolved.
Show resolved Hide resolved
n *= 60;
n = Math.floor(n).toString();
n = n.length < 2 ? '0'.concat(n) : n.substring(0, 2);
entry = entry.substring(0, periodIdx).concat(':').concat(n);
/* istanbul ignore else */
if (periodIdx <= 1)
{
// only 1 digit before .
entry = '0'.concat(entry);
}
}
else
{
// no . or :
/* istanbul ignore else */
if (entry.length < 2)
{
entry = '0'.concat(entry);
}
entry = entry.concat(':00');
}
this.value = entry;
changeValue(this.name, entry);
}
});

Expand Down