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

687-platform-usage-updates #828

Merged
merged 3 commits into from
Sep 28, 2023
Merged

687-platform-usage-updates #828

merged 3 commits into from
Sep 28, 2023

Conversation

alishaevn
Copy link
Contributor

@alishaevn alishaevn commented Sep 27, 2023

Story

first issue

accounting for begin/end dates passed as MM/YYYY.

This is necessary because calling to_date on a string in MM-YYYY format will assume that MM is the day, and will set the current month as MM instead.

We are also still allowing for dates to use MM-DD-YYYY format.

params.fetch(:begin_date) => "06-2023"
params.fetch(:begin_date).to_date => Wed, 06 Sep 2023

second issue

accounting for exceptions in the report header

exception 0 is a special case, as it represents info or debugging messages.
when the query is successful, despite the exception, the exception is
to be returned as part of the report header.

ref: https://countermetrics.stoplight.io/docs/counter-sushi-api/jmelferytrixm-exception-0
ref: #687 (comment)

Screenshots / Video

MM-YYYY format

image

YYYY-MM-DD format image

This is necessary because calling `to_date` on a string in 'MM-YYYY'
format will assume that 'MM' is the day, and will set the current month
as 'MM' instead.

params.fetch(:begin_date) => "06-2023"
params.fetch(:begin_date).to_date => Wed, 06 Sep 2023

We are also still allowing for dates to use MM-DD-YYYY format.

'2023-06-10'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/)
	=> #<MatchData "2023-06-10" 1:nil 2:"2023-06-10">
'2023-06'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/)
	=> #<MatchData "2023-06" 1:"2023-06" 2:nil>
'06-2023'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/)
	=> nil

ref: #687 (comment)
exception 0 is a special case, as it represents info or debugging messages.
when the query is successful, despite the exception, the exception is
to be returned as part of the report header.

ref: https://countermetrics.stoplight.io/docs/counter-sushi-api/jmelferytrixm-exception-0
ref: #687 (comment)
# params.fetch(:begin_date).to_date => Wed, 06 Sep 2023
def validate_date_format(dates = [])
dates.each do |date|
match = date.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'2023-06-10'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/) => #<MatchData "2023-06-10" 1:nil 2:"2023-06-10">
'2023-06'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/) => #<MatchData "2023-06" 1:"2023-06" 2:nil>
'06-2023'.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/) => nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write tests for these? Regular expressions are notorious for missing use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremyf other than the two specs in sushi_spec.rb?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I completely mentally skipped over those.

@alishaevn alishaevn marked this pull request as ready for review September 28, 2023 19:16
@alishaevn alishaevn marked this pull request as draft September 28, 2023 19:17
# params.fetch(:begin_date).to_date => Wed, 06 Sep 2023
def validate_date_format(dates = [])
dates.each do |date|
match = date.match(/(^\d{4}-\d{2}$)|(^\d{4}-\d{2}-\d{2}$)/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write tests for these? Regular expressions are notorious for missing use cases.

@alishaevn alishaevn marked this pull request as ready for review September 28, 2023 19:44
@labradford labradford merged commit a2ff4f6 into main Sep 28, 2023
@labradford labradford deleted the 687-platform-usage-updates branch September 28, 2023 23:27
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