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

Adding datetime type #1206

Closed
fabricereix opened this issue Jan 26, 2023 · 8 comments · Fixed by #1227
Closed

Adding datetime type #1206

fabricereix opened this issue Jan 26, 2023 · 8 comments · Fixed by #1227
Labels
enhancement New feature or request
Milestone

Comments

@fabricereix
Copy link
Collaborator

Add a datetime type to the possible values (returned by a query or filter).
One of the motivations is using reusable filters such as daysFromNow, year, ...

format/parse filters will have to be used to convert Date to String/String to Date.

The datetime format can be specified explicitely (https://docs.rs/chrono/latest/chrono/format/strftime/)
formatDate "%y/%m/%d" :: date -> str
parseDate "%y/%m/%d" :: str -> date

Example
The query cookie "SESSION_ID[Expires]" could return a datetime value.
cookie "SESSION_ID[Expires]" formatDate "%y/%m/%d %H:%M:%S" == "2021/01/13 22:23:01"
cookie "SESSION_ID[Expires]" formatDate "%y" == "2021"

The header query always returns a String, thus, its value could be converted explicitly.
header "Expires" parseDate "%a, %d %b %H/%M/%S"

We could also add specific parse methods:
header "Expires" parseDateRFC822 year == 2022

Similarly with formatting
cookie "SESSION_ID[Expires]" formatDateRFC822 == "Tue, 1 Jul 2003 10:52:37 +0200"

For the == predicate,
we could maybe accept date_value == string_value
where the string_value is parsed automatically/implicitly as a date (tries common date format)
That will enable to keep the existing assert
cookie "SESSION_ID[Expires]" == "Wed, 13 Jan 2021 22:23:01 GMT"

@fabricereix fabricereix added the enhancement New feature or request label Jan 26, 2023
@fabricereix
Copy link
Collaborator Author

fabricereix commented Jan 26, 2023

or the queries do not return dates (as now) and the values always needs to be converted explictly.
cookie "SESSION_ID[Expires]" == "Wed, 13 Jan 2021 22:23:01 GMT" is still an equality of strings.

Using date filter
cookie "SESSION_ID[Expires]" parseDateRFC822 minutesFromNow < 15
or
cookie "SESSION_ID[Expires]" toDateRFC822 minutesFromNow < 15
or
cookie "SESSION_ID[Expires]" toDate minutesFromNow < 15 where toDate tries specific common formats (RFC822, ...)

@jcamiel
Copy link
Collaborator

jcamiel commented Jan 26, 2023

I prefer that cookie "SESSION_ID[Expires]" returns a Date type. The format is standard (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date) so there is no point to ask the user to provide the right format to parse this string.

@lepapareil
Copy link
Collaborator

What about :

For the == predicate,
we could maybe accept date_value == string_value
where the string_value is parsed automatically/implicitly as a date (tries common date format)
That will enable to keep the existing assert
cookie "SESSION_ID[Expires]" == "Wed, 13 Jan 2021 22:23:01 GMT"

@jcamiel ?

@jcamiel
Copy link
Collaborator

jcamiel commented Jan 26, 2023

I the cookie "Expires" query returns only a Date, you can still have the string value:

Either use a header query:

header "Set-Cookie" regex /SESSION_ID=.*Expires=(.*?);/ == "Wed, 13 Jan 2021 22:23:01 GMT"

Or use a filter on cookie query:

cookie "SESSION_ID[Expires]" formatDate "%y/%m/%d %H:%M:%S" == "2021/01/13 22:23:01"

I prefer the query to return only one type, instead of the query type being dependent on the predicate value.

@fabricereix
Copy link
Collaborator Author

fabricereix commented Jan 28, 2023

relating to the naming of the datetime filters,
parseDatetime/formatDatetime versus datetimeParse/datetimeFormat ?

I would tend to prefer the second form to be consistent with htmlEscape/htmlUnescape
We should also probably use the fullname datetime everywhere rather date.
We will not have (at least for the time-being) a value that does not include the time.

we could also have a more generic filter format "FORMAT_STRING" that will depend on the value type.
format "%06d" for an integer value
format "%.2f" for a float input
format "%y/%m/%d for a datetime value

@fabricereix
Copy link
Collaborator Author

fabricereix commented Jan 28, 2023

Example with format
cookie "SESSION_ID[Expires]" returns a datetime value

cookie "SESSION_ID[Expires]" format "%y"== "2021"
cookie "SESSION_ID[Expires]" year == 2021

@jcamiel
Copy link
Collaborator

jcamiel commented Jan 30, 2023

"Final" syntax:

GET https://foo.com
HTTP 200
[Asserts]
cookie "SESSION_ID[Expires]" minutesFromNow < 15
cookie "SESSION_ID[Expires]" yearsFromNow < 15
cookie "SESSION_ID[Expires]" year == 2021
cookie "SESSION_ID[Expires]" format "%y" == "2021"
header "Expires" toDate "%a, %d %b  %H/%M/%S" == "Wed, 13 Jan 2021 22:23:01 GMT"
header "Expires" toDateRFC822 year == 2021

@fabricereix
Copy link
Collaborator Author

The Date type will also implicity encapsulates the time (like javascript Date (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

@jcamiel jcamiel added this to the 3.0.0 milestone Mar 23, 2023
@jcamiel jcamiel linked a pull request Mar 23, 2023 that will close this issue
@jcamiel jcamiel closed this as completed Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants