Fomantic-UI
Fomantic-UI copied to clipboard
[Calendar] wrong datetime parsing
Bug Report
Actual develop branch seems to wrongly parse datetime in calendar module.
Culprit seems to come from this commit: 8a331f0e62806964cfa00c271b09d54076f28df5.
In src\definitions\modules\calendar.js
at line 1563.
text = String(text).trim();
has been replaced by
text = String(text).replace(/\s/g,'');
When this line is reverted, date parsing is correct.
Steps to reproduce
- Create a minimal calendar.
- Set initial date by
data-date="2022-03-17 09:35:00"
ordata-value="2022-03-17 09:35:00"
. - Initialize the calendar module.
Expected result
March 17, 2022 9:35 AM
Actual result
March 1, 2022 5:35 AM
Testcase
Screenshot (if possible)
Version
2.9@nightly
Indeed... Reason for that was #2200 where whitespace was messing up the parsing "10. 6. 2021" I play around with a better regex instead of just removing any whitespace, because just reverting this line would again introduce the other bug. Thanks for pointing this out!
If it helps, there are a bunch of different date formats here: https://en.wikipedia.org/wiki/Date_format_by_country
The trouble is supporting all of them could make the regex somewhat difficult
Thinking outside the box, could it be that an additional option is available for the calendar where an input date format is provided in order to parse the date into JavaScript correctly. Something like…
$(‘.ui.calendar’).calendar({
format: “dd. mm. yyyy”,
});
This could then be used for time as well as datetime formats
Naturally the default format should probably be yyyy-mm-dd
It could even be that there is an inputFormat
as well as an outputFormat
(granted, formatter
could be used for the output format, but this could be considered a far more simple approach if nothing fancy needs to happen in terms of logic/processes), where, by default, output matches input if output isn’t provided
@prudho Fixed by https://github.com/fomantic/Fomantic-UI/pull/2275 as discussed (focussing on whitespace so the parser works again)
@jamessampford Regarding a general format (for output formatting), was requested in #568 already.
@prudho Here is your fiddle using the patch https://jsfiddle.net/lubber/23y5mc0h/