diff --git a/README.md b/README.md index 900e9f76..db0ae2fc 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/public/viewjs/components/datetimepicker.js b/public/viewjs/components/datetimepicker.js index f15a14f7..0b156cc4 100644 --- a/public/viewjs/components/datetimepicker.js +++ b/public/viewjs/components/datetimepicker.js @@ -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))