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

Add isIsoDate predicate #2427

Closed
jcamiel opened this issue Feb 14, 2024 · 5 comments
Closed

Add isIsoDate predicate #2427

jcamiel opened this issue Feb 14, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers topic: predicates
Milestone

Comments

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 14, 2024

The current isDate predicate takes "date" type as input. To use it on a string, user has to explicitly convert it to a date using a format spec and toDate filter:

POST https://foo.com
HTTP 200
[Asserts]
jsonpath "$.created" toDate "%Y-%m-%dT%H:%M:%S%.f%:z" isDate

As the user must explicitly transform the string to a date, isDate has little value.

Proposal

Add a isIsoDate predicate that take a string as input and check that this string can be converted to a date with the format spec %Y-%m-%dT%H:%M:%S%.f%:z(chrono format).

Like Date.parse and Date.propotype.toISOString JavaScript methods, we're only checking the JavaScript date time string format YYYY-MM-DDTHH:mm:ss.sssZ (simplicification of the ISO 8601)

POST https://foo.com
HTTP 200
[Asserts]
jsonpath "$.created" isIsoDate
@jcamiel jcamiel added enhancement New feature or request topic: predicates labels Feb 14, 2024
@jcamiel jcamiel changed the title New isIsoDate predicates Add isIsoDate predicate Feb 14, 2024
@jcamiel jcamiel added the good first issue Good for newcomers label Feb 15, 2024
@beaterblank
Copy link

I'd like to take this issue, very similar to isDate predicate so I should be able to implement a similar flow.

@beaterblank
Copy link

beaterblank commented Feb 19, 2024

NaiveDateTime::parse_from_str with %Y-%m-%dT%H:%M:%S%.f%:z" does not work for some reason but removing the % after f makes it work.

what about the time format %Y-%m-%dT%H:%M:%S%.fZ ? should we also consider this as an iso date while testing?

I was thinking of using this high level logic :

use chrono::NaiveDateTime;

fn main() {
    const DATE_FMTS : [&str;2] = ["%Y-%m-%dT%H:%M:%S%.f:z","%Y-%m-%dT%H:%M:%S%.fZ"];
    for fmt in DATE_FMTS{
        if let Ok(_) = NaiveDateTime::parse_from_str(" 2024-02-15T19:47:46.266:z",fmt){
            println!("matched with {}",fmt);
        }
    }
}

Also, I've used ISO string as the expected value type for this is this okay should I just keep it string ?

@beaterblank
Copy link

Please check the PR for above things and let me know if any feedback. Thank you!

@jcamiel
Copy link
Collaborator Author

jcamiel commented Feb 19, 2024

Hi @beaterblank I'll make feedback asap

@jcamiel
Copy link
Collaborator Author

jcamiel commented Mar 21, 2024

Hi @beaterblank this has been fixed by #2565. I'm. closing this one now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers topic: predicates
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants