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: Width formatting is not respected without a separator #546

Closed
JAMSUPREME opened this issue Oct 15, 2021 · 1 comment
Closed

toMillis: Width formatting is not respected without a separator #546

JAMSUPREME opened this issue Oct 15, 2021 · 1 comment

Comments

@JAMSUPREME
Copy link
Contributor

JAMSUPREME commented Oct 15, 2021

Bug Summary

Width formatting doesn't appear to be respected without a separator.

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

Suggested Fix

I attempted a fix but you can let me know whether or not it's reasonable: #545

Work-around

I made a little helper function to grab the fixed-width portions of year/month/date via substring and then reformat the string prior to sending it to toMillis:

const dateFunc = `
  $dateYMD := function($date) {( 
    $year := $substring($date, 0, 4);
    $month := $substring($date, 4, 2);
    $day := $substring($date, 6, 2);
    $year & '-' & $month & '-' & $day
  )};
`;

The library then functions as expected once the date string has been split via separators.

@JAMSUPREME JAMSUPREME changed the title Width formatting is not respected without a separator toMillis: Width formatting is not respected without a separator Oct 15, 2021
@JAMSUPREME
Copy link
Contributor Author

Closing. Fixed via #545

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

No branches or pull requests

1 participant