Skip to content

Instantly share code, notes, and snippets.

@ova2
Last active August 29, 2015 13:57
Show Gist options
  • Save ova2/9531751 to your computer and use it in GitHub Desktop.
Save ova2/9531751 to your computer and use it in GitHub Desktop.
Bug in CSV with date / time converter
Client-side conversion / validation fails in most cases for f:convertDateTime and valid dates / times
PrimeFaces 4.x (current)
The client-side converter for f:convertDateTime uses $.datepicker.parseDate(format, value, settings).
The problem with $.datepicker.parseDate ist an exception when the format doesn't have days
(works as designed). E.g. try to parse $.datepicker.parseDate("mm/y", "11/16").
An exception will be raised. "mm/y" for datepicker is exactly the pattern "MM/yy" in
f:convertDateTime. Simple attach e.g. <f:convertDateTime pattern="MM/yy" timeZone="..."/>
to p:inputText and use CSV. The date will be always invalid.
The same is for only time. The pattern "HH:mm" can not be converted / validated by CVS.
Try $.datepicker.parseDate or $.datepicker.parseTime in the FF / Chrome console on any
PF page with calendar. A time in format "HH:mm" or "hh:mm" is always invalid by CSV.
That means we can not use <f:convertDateTime pattern="HH:mm" .../>
To overcome this issue I parse these formats manuelly without $.datepicker.parseDate
in an own client-side converter (tricky but works).
It also work with moment.js (http://momentjs.com) or similar libs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment