hurl
hurl copied to clipboard
Add isIsoDate predicate
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
andDate.propotype.toISOString
JavaScript methods, we're only checking the JavaScript date time string formatYYYY-MM-DDTHH:mm:ss.sssZ
(simplicification of the ISO 8601)
POST https://foo.com
HTTP 200
[Asserts]
jsonpath "$.created" isIsoDate
I'd like to take this issue, very similar to isDate
predicate so I should be able to implement a similar flow.
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
?
Please check the PR for above things and let me know if any feedback. Thank you!
Hi @beaterblank I'll make feedback asap
Hi @beaterblank this has been fixed by #2565. I'm. closing this one now