-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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}$)/) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
# 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}$)/) |
There was a problem hiding this comment.
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.
Story
first issue
accounting for begin/end dates passed as
MM/YYYY
.This is necessary because calling
to_date
on a string inMM-YYYY
format will assume thatMM
is the day, and will set the current month asMM
instead.We are also still allowing for dates to use
MM-DD-YYYY
format.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
YYYY-MM-DD format