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

toMillis: Allow width formatting without separators #545

Merged
merged 13 commits into from
Nov 2, 2021

Conversation

JAMSUPREME
Copy link
Contributor

@JAMSUPREME JAMSUPREME commented Oct 15, 2021

Bug Summary

Width formatting doesn't appear to be respected without a separator. Corresponding issue: #546

Versions

JSONata 1.8.5
Node v14.17.0

Detailed Information

Reference spec for width formatting: https://www.w3.org/TR/xpath-functions-31/#date-time-examples

At the moment, it appears the width formatting is not honored within $toMillis due to the way the regex is being generated. For an example input 201802, I should be able to specify a matcher [Y0001][M01] which will result in a parsed value of 2018/02/01. At the moment, the library incorrectly grabs too many characters due to the + regex so I end up with 20180/02/01

Test Cases

Input Picture Output (timestamp) Output (pretty)
201802 [Y0001][M01] 1517443200000 Thu, 01 Feb 2018 00:00:00 GMT
201802 [Y,*-4][M01] 1517443200000 Thu, 01 Feb 2018 00:00:00 GMT
20180205 [Y0001][M01][D01]] 1517788800000 Mon, 05 Feb 2018 00:00:00 GMT

@coveralls
Copy link

coveralls commented Oct 15, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 0e06675 on JAMSUPREME:regex-issue into ed1dacf on jsonata-js:master.

@JAMSUPREME JAMSUPREME changed the title Allow width formatting without separators toMillis: Allow width formatting without separators Oct 15, 2021
Adding a YMD case which appears to be failing.
Usage of n works except when there could be optional digits, i.e. [M#1] in which case we need to also supply a lower bound of occurrences.
Copy link
Member

@andrew-coleman andrew-coleman left a comment

Choose a reason for hiding this comment

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

Looks good. Many thanks!

@mattbaileyuk mattbaileyuk merged commit e6e436d into jsonata-js:master Nov 2, 2021
@JAMSUPREME JAMSUPREME deleted the regex-issue branch November 2, 2021 13:23
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.

4 participants