-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip timezone from POST params (#20790)
* Strip timezone from POST params * Fix linter * Removed redundant error handling * Linter * Adjust param casing * update casing for param * Updated casing on swagger docs * update param position * Corrected swagger --------- Co-authored-by: stevenjcumming <[email protected]>
- Loading branch information
1 parent
14a95cc
commit 6a7fbb7
Showing
9 changed files
with
64 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module TravelPay | ||
module DateUtils | ||
def self.strip_timezone(time) | ||
# take the time and parse it as a Time object if necessary | ||
# convert it to an array of its parts - zone will be nil | ||
# create a new time with those parts, using the nil timezone | ||
t = try_parse_date(time) | ||
time_parts = %i[year month day hour min sec] | ||
Time.utc(*t.deconstruct_keys(time_parts).values) | ||
end | ||
|
||
def self.try_parse_date(datetime) | ||
raise InvalidComparableError.new('Provided datetime is nil.', datetime) if datetime.nil? | ||
|
||
return datetime.to_time if datetime.is_a?(Time) || datetime.is_a?(Date) | ||
|
||
# Disabled Rails/Timezone rule because we don't care about the tz in this dojo. | ||
# If we parse it any other 'recommended' way, the time will be converted based | ||
# on the timezone, and the datetimes won't match | ||
Time.parse(datetime) if datetime.is_a? String # rubocop:disable Rails/TimeZone | ||
end | ||
|
||
def self.try_parse_date_range(start_date, end_date) | ||
unless start_date && end_date | ||
raise ArgumentError, | ||
message: "Both start and end dates are required, got #{start_date}-#{end_date}." | ||
end | ||
|
||
{ start_date: try_parse_date(start_date), end_date: try_parse_date(end_date) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters