-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
DKAN: Fix date conversion to accept "DD-MM-YYYY HH:MM" format #231
Conversation
this accepts - and / as date separators and just whitespace chars between date and time
<xsl:variable name="regExLoc">^.*([0-9]{2})/([0-9]{2})/([0-9]{4}) - ([0-9]{2}:[0-9]{2})$</xsl:variable> | ||
<!-- example of internationalized date: "2020-12-09 00:00:00" --> | ||
<!-- examples of localized date: "jeu, 24/12/2020 - 03:00", "24-12-2020 03:00" --> | ||
<xsl:variable name="regExLoc">^.*([0-9]{2})[-/]([0-9]{2})[-/]([0-9]{4})\s+([0-9]{2}:[0-9]{2})$</xsl:variable> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok to accept -
or /
, but did you notice that the format is different as well ?
eg "metadata_created": "11-03-2021 14:00",
is DD-MM-YYYY
and not YYYY-MM-DD
It means that the comment below is deprecated cause the expression does not support this format 2020-12-09 00:00:00
I mentioned that DKAN seems to output all kinds of date format, see https://opendata.hautsdefrance.fr/?q=api/3/action/current_package_list_with_resources which should be supported as well.
Also don't you forget the \
before the slash ? I had to add them to test the regexp on https://regex101.com/
^.*([0-9]{2})[-\/]([0-9]{2})[-\/]([0-9]{4})\s+([0-9]{2}:[0-9]{2})$
But maybe in XSL it's ok
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback !
The date format 2020-12-09 00:00:00
is handled by the regExInt
one line below.
Indeed, the \
is apparently not supported in XSL here (causing "invalid escape sequence" errors). https://regexr.com/ does not reclaim it, neither.
I've added the potential -
separator between date and time (which I forgot) and added accepting optional seconds (which will not be used via the capturing group but stay :00
for the sake of simplicity).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it match 2020-12-09 00:00:00
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one does I think, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes sorry looks good !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, it covers all formats (so far 😄 )
PR makes
regExLoc
for localized date conversion more permissive. Now accepts-
and/
as date separators and just whitespace chars between date and time. This allows date formats such as31-03-2023 00:15
in addition to the current "jeu,24/12/2020 - 03:00
.IMO, it makes sense to make the existing regexp more permissive, as this will also allow similar formats like
jeu, 24/12/2020 03:00
24/12/2020 03:00
24-12-2020 - 03:00
A more restrictive alternative would be to add a separate regexp and matching condition :