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

feat: add matchers for ISO 8601 date format #333

Merged
merged 1 commit into from
Apr 29, 2023

Conversation

sergeyklay
Copy link
Member

@sergeyklay sergeyklay commented Mar 12, 2023

This introduces pact.Format.iso_8601_datetime() method to match a string for a full ISO 8601 Date.

This method does not do any sort of date validation, only checks if the string is according to the ISO 8601 spec.

It differs from pact.Format.timestamp, pact.Format.date and pact.Format.time implementations in that it is more stringent and tests the string for exact match to the ISO 8601 dates format.

Without with_ms parameter will match string containing ISO 8601 formatted dates as stated bellow:

  • 2016-12-15T20:16:01
  • 2010-05-01T01:14:31.876
  • 2016-05-24T15:54:14.00000Z
  • 1994-11-05T08:15:30-05:00
  • 2002-01-31T23:00:00.1234-02:00
  • 1991-02-20T06:35:26.079043+00:00

Otherwise, ONLY dates with milliseconds will match the pattern:

  • 2010-05-01T01:14:31.876
  • 2016-05-24T15:54:14.00000Z
  • 2002-01-31T23:00:00.1234-02:00
  • 1991-02-20T06:35:26.079043+00:00

This change aims to bring the capabilities of the python library into alignment with pact-foundation/docs.pact.io#88, since the existing functionality is a bit liberal and allows tests to pass even in cases where the dates do not conform to the ISO 8601 spec.

This introduces `pact.Format.iso_8601_datetime()` method to match a
string for a full ISO 8601 Date.

This method does not do any sort of date validation, only checks if
the string is according to the ISO 8601 spec.

It differs from `pact.Format.timestamp`, `pact.Format.date` and
`pact.Format.time` implementations in that it is more stringent
and tests the string for exact match to the ISO 8601 dates format.

Without `with_ms` parameter will match string containing ISO 8601
formatted dates as stated bellow:

* 2016-12-15T20:16:01
* 2010-05-01T01:14:31.876
* 2016-05-24T15:54:14.00000Z
* 1994-11-05T08:15:30-05:00
* 2002-01-31T23:00:00.1234-02:00
* 1991-02-20T06:35:26.079043+00:00

Otherwise, ONLY dates with milliseconds will match the pattern:

* 2010-05-01T01:14:31.876
* 2016-05-24T15:54:14.00000Z
* 2002-01-31T23:00:00.1234-02:00
* 1991-02-20T06:35:26.079043+00:00

This change aims to bring the capabilities of the python library into
alignment with pact-foundation/docs.pact.io#88, since the existing
functionality is a bit liberal and allows tests to pass even in cases
where the dates do not conform to the ISO 8601 spec.
Copy link
Member

@mefellows mefellows 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! The only comment I have is that other languages let you specify the example value, whereas in this matcher it's hard coded.

It's consistent with the other matchers, so I think it's OK, but wanted to share that feedback.

@sergeyklay
Copy link
Member Author

sergeyklay commented Apr 3, 2023

@mefellows I'll definitely fix this, thank you for your comment. However, I would like to address it in a separate pull request. The issue is that there is currently hardcoded logic in all matchers, and I'd prefer to make a single, unified change to address this.

@mefellows
Copy link
Member

Absolutely! Let's not hold up this change for that.

@YOU54F
Copy link
Member

YOU54F commented Apr 29, 2023

Nice one, we've got a flakey build, but you get a mergey merge ( i just got one merging a docco change :( )

@YOU54F
Copy link
Member

YOU54F commented Apr 29, 2023

also thanks for updating the readme and adding a test

@YOU54F YOU54F merged commit e037772 into pact-foundation:master Apr 29, 2023
@sergeyklay sergeyklay deleted the feature/iso-dates branch April 29, 2023 07:18
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.

3 participants