Skip to content
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

Merged
merged 2 commits into from
Apr 11, 2023

Conversation

tkohr
Copy link
Contributor

@tkohr tkohr commented Apr 7, 2023

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 as 31-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 :

<!-- example of custom date: "24-12-2020 00:00" -->
<xsl:variable name="regExCustom">^([0-9]{2})-([0-9]{2})-([0-9]{4}) ([0-9]{2}:[0-9]{2})$</xsl:variable>

<xsl:when test="matches($value, $regExCustom)">
  <xsl:value-of select="replace($value, $regExCustom, '$3-$2-$1T$4:00')"></xsl:value-of>
</xsl:when>

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>
Copy link
Member

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

Copy link
Contributor Author

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).

Copy link
Member

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 ?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry looks good !

Copy link
Member

@fgravin fgravin left a 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 😄 )

@tkohr tkohr merged commit 031d73d into georchestra-gn4.2.x Apr 11, 2023
@tkohr tkohr deleted the geor-dkan-date branch April 11, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants