Improve date picker MMDD shorthand

This commit is contained in:
Bernd Bestel 2018-07-22 13:09:23 +02:00
parent b1522742cc
commit e9a4b43268
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 7 additions and 2 deletions

View File

@ -36,7 +36,7 @@ Some fields also allow to select a value by scanning a barcode. It works best wh
### Input shorthands for date fields
For (productivity) reasons all date (and time) input fields use the ISO-8601 format regardless of localization.
The following shorthands are available:
- `MMDD` gets expanded to the given day on the current year in proper notation
- `MMDD` gets expanded to the given day on the current year, if > today, or to the given day next year, if < today, in proper notation
- Example: `0517` will be converted to `2018-05-17`
- `YYYYMMDD` gets expanded to the proper ISO-8601 notation
- Example: `20190417` will be converted to `2019-04-17`

View File

@ -93,7 +93,12 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e)
}
else if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd))
{
Grocy.Components.DateTimePicker.SetValue((new Date()).getFullYear().toString() + value);
var date = moment((new Date()).getFullYear().toString() + value);
if (date.isBefore(moment()))
{
date.add(1, "year");
}
Grocy.Components.DateTimePicker.SetValue(date.format(format));
nextInputElement.focus();
}
else if (value.length === 8 && $.isNumeric(value))