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

Support timezones for Puerto Rico #8225

Merged
merged 2 commits into from
Oct 31, 2024
Merged

Conversation

emyl3
Copy link
Collaborator

@emyl3 emyl3 commented Oct 23, 2024

BACKEND PULL REQUEST

Related Issue

Changes Proposed

  • Fixes a bug in our CSV bulk uploader where we were generating a timezone for date values in the following columns:
    order_test_date, specimen_collection_date, testing_lab_specimen_received_date, test_result_date, date_result_released
    • this bug occurred for any valid ordering provider address in Puerto Rico AND when the above columns had only a date value OR date and time value without a timezone (e.g. 10/18/2024 or 10/18/2024 12:00 and NOT 10/18/2024 12:00 ET)
  • Added the timezone abbreviations for Puerto Rico (AST and ADT) so that these timezones can be used in dates for our bulk uploader and pass validation

Additional Information

  • N/A

Testing

  • example CSV with a VALID Puerto Rico ordering provider and no timestamps - pr_ordering_provider_ex.csv
    • should fail silently on main
    • should succeed on dev3
    • editing the file and adding AST or ADT to any date timestamps should also pass the validations

@@ -144,6 +145,7 @@ public ZoneId getZoneIdByLookup(Lookup lookup) {
return null;
}

return ZoneId.of("US/" + timezoneInfo.timezoneCommonName);
Copy link
Collaborator Author

@emyl3 emyl3 Oct 24, 2024

Choose a reason for hiding this comment

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

⚠️ For a valid Puerto Rico address, we were getting back Atlantic for timezoneInfo.timezoneCommonName.
If you see the list here, US/Atlantic doesn't exist and was throwing an exception.

Decided to get the ZoneId using the ZoneOffset value instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think using the ZoneOffset might run into issues with whether ZoneId.of() is returning the correct zone since it would change based on whether the zone obeys daylight savings time or not. The slight inaccuracy might not matter, but the original issue that forced us to start handling time zones in bulk upload was a STLT having issues with some of their data being marked as an incorrect day due to time wackiness. Wondering if it would be better in this case to just specifically handle the Atlantic time zone and still use the existing US/commonName to handle the other time zones since Smartystreets is still able to pinpoint what time zone the address is in compared to the possible ambiguity with utcOffset? I wish Smartystreets simply returned the official time zone rather than just the common name 😩

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OOO thank you for this context, Mike! I will rethink my implementation!

@@ -37,6 +37,7 @@ public class DateTimeUtils {
private static final ZoneId hawaiiTimeZoneId = ZoneId.of("US/Hawaii");
private static final ZoneId aleutianTimeZoneId = ZoneId.of("US/Aleutian");
private static final ZoneId samoaTimeZoneId = ZoneId.of("US/Samoa");
private static final ZoneId puertoRicoTimeZoneId = ZoneId.of("America/Puerto_Rico");
Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to specifically handling Puerto Rico, I think it makes sense to catch whatever exception was being thrown and default the timezone to something (eastern time?). If this is a big deal we can add alerting for when it happens, but I think the failure state should be that the file still gets uploaded successfully.

Do we know how the single entry flow was handling this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re: handling the exception

Based on the fix implemented I don't think there would be an exception thrown anymore.

Because we were doing this before

return ZoneId.of("US/" + timezoneInfo.timezoneCommonName);

if timezoneInfo.timezoneCommonName returned something like Atlantic (like the valid Puerto Rico address did), we'd be trying to get the ZoneId.of("US/Atlantic") which would throw the exception.

Now, since we are using the timezoneInfo.utcOffset value instead of creating strings (that potentially don't exist) we should be good. If timezoneInfo == null we already return null. The method that calls getZoneIdByAddress sets the default timezone (eastern time) if the value is null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re: single entry flow
I believe this is how we are handling it. We aren't extracting any timezone data from the ordering provider so we would not run into the same issue in the single entry flow based on my read of this 👀

@@ -62,9 +63,9 @@ public class DateTimeUtils {
Map.entry("HI", hawaiiTimeZoneId),
Map.entry("HST", hawaiiTimeZoneId),
Map.entry("HDT", aleutianTimeZoneId),
Map.entry("AS", samoaTimeZoneId),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ removed "AS" and "ASM" because I don't think they are actually timezones for American Samoa based on this list Let me know if I should be using a different list 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally we should use the IANA Time Zone Database. The wiki page here has the latest 2024 list.

For this particular map, IIRC we wanted to allow users to include these valid time zone abbreviations in their upload since some people still use AS or ASM. For example, this site still includes AS and ASM as abbreviations even though the ISO official time zone is SST.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OOO thank you for letting me know! I'll take a look!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added "AS" and "ASM" back

@emyl3 emyl3 marked this pull request as ready for review October 25, 2024 20:47
@emyl3 emyl3 requested a review from DanielSass October 25, 2024 20:57
Copy link
Collaborator

@mpbrown mpbrown left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this! Left some questions about whether we can rely on utc offset vs the geolocated time zone name from smarty

@@ -62,9 +63,9 @@ public class DateTimeUtils {
Map.entry("HI", hawaiiTimeZoneId),
Map.entry("HST", hawaiiTimeZoneId),
Map.entry("HDT", aleutianTimeZoneId),
Map.entry("AS", samoaTimeZoneId),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally we should use the IANA Time Zone Database. The wiki page here has the latest 2024 list.

For this particular map, IIRC we wanted to allow users to include these valid time zone abbreviations in their upload since some people still use AS or ASM. For example, this site still includes AS and ASM as abbreviations even though the ISO official time zone is SST.

@@ -144,6 +145,7 @@ public ZoneId getZoneIdByLookup(Lookup lookup) {
return null;
}

return ZoneId.of("US/" + timezoneInfo.timezoneCommonName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think using the ZoneOffset might run into issues with whether ZoneId.of() is returning the correct zone since it would change based on whether the zone obeys daylight savings time or not. The slight inaccuracy might not matter, but the original issue that forced us to start handling time zones in bulk upload was a STLT having issues with some of their data being marked as an incorrect day due to time wackiness. Wondering if it would be better in this case to just specifically handle the Atlantic time zone and still use the existing US/commonName to handle the other time zones since Smartystreets is still able to pinpoint what time zone the address is in compared to the possible ambiguity with utcOffset? I wish Smartystreets simply returned the official time zone rather than just the common name 😩

@emyl3 emyl3 marked this pull request as draft October 28, 2024 15:43
@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 28, 2024

Back in draft while I address Mike's comments! - PLEASE DO NOT REVIEW!

@emyl3 emyl3 force-pushed the elisa/8203-PR-timezone-support branch from 498ff68 to 1720d18 Compare October 29, 2024 19:39
Copy link

* Map of common name `time_zone` values returned from SmartyStreets and their corresponding
* ZoneId https://www.smarty.com/docs/cloud/us-street-api
*/
public static final Map<String, ZoneId> commonNameZoneIdMap =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ explicitly mapped all the possible SmartyStreets time_zone common names that could be returned to specific ZoneIds

Copy link
Collaborator

Choose a reason for hiding this comment

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

strange that they use this list instead of something more standard

* Map of abbreviated timezones and their corresponding ZoneId Used for bulk upload timestamp
* validations and when converting user-supplied timezones to a ZoneId
*/
public static final Map<String, ZoneId> timezoneAbbreviationZoneIdMap =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ renamed from validTimeZoneIdMap to hopefully be more descriptive 😅

@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 29, 2024

Ready for review again! @mpbrown @mehansen @bobbywells52 @DanielSass

@emyl3 emyl3 requested a review from mpbrown October 29, 2024 20:40
@mpbrown
Copy link
Collaborator

mpbrown commented Oct 29, 2024

The example file worked for dev3, but when I edited it to include the time zones within the date time values, it gave me these errors 🤔

Screenshot 2024-10-29 174503

Here's the edited copy that I tried on dev3
pr_ordering_provider_ex_edit.csv

Also I noticed in the example file that we're using M/D/YYYY HH:mm:ss PM and wondering whether it currently tries to interpret PM as a time zone abbreviation. This could probably be a separate ticket, but maybe we should either explicitly handle if the user puts in AM/PM or update the guide to tell them not to put AM/PM in addition to a time zone (I could see some users not wanting to use 24H notation vs 12H notation though) 😮‍💨

@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 30, 2024

The example file worked for dev3, but when I edited it to include the time zones within the date time values, it gave me these errors 🤔

Screenshot 2024-10-29 174503

Here's the edited copy that I tried on dev3 pr_ordering_provider_ex_edit.csv

Also I noticed in the example file that we're using M/D/YYYY HH:mm:ss PM and wondering whether it currently tries to interpret PM as a time zone abbreviation. This could probably be a separate ticket, but maybe we should either explicitly handle if the user puts in AM/PM or update the guide to tell them not to put AM/PM in addition to a time zone (I could see some users not wanting to use 24H notation vs 12H notation though) 😮‍💨

OO I checked that file and noticed that there's an extra whitespace in between the date and time so it was failing the DATE_TIME_REGEX check.

I could add that as part of the ticket you alluded to to make our DATE_TIME_REGEX a little bit more robust. Does that work, Mike? 🤔

@mpbrown
Copy link
Collaborator

mpbrown commented Oct 30, 2024

The example file worked for dev3, but when I edited it to include the time zones within the date time values, it gave me these errors 🤔
Screenshot 2024-10-29 174503
Here's the edited copy that I tried on dev3 pr_ordering_provider_ex_edit.csv
Also I noticed in the example file that we're using M/D/YYYY HH:mm:ss PM and wondering whether it currently tries to interpret PM as a time zone abbreviation. This could probably be a separate ticket, but maybe we should either explicitly handle if the user puts in AM/PM or update the guide to tell them not to put AM/PM in addition to a time zone (I could see some users not wanting to use 24H notation vs 12H notation though) 😮‍💨

OO I checked that file and noticed that there's an extra whitespace in between the date and time so it was failing the DATE_TIME_REGEX check.

I could add that as part of the ticket you alluded to to make our DATE_TIME_REGEX a little bit more robust. Does that work, Mike? 🤔

Ooof my bad, I used excel to edit the csv and forgot that excel adds a bunch of autoformatting on save which ends up messing with the csv 😬 Those edited time zones work as expected on dev3 now!

I think it makes sense to create another ticket since we'll want to check with the rest of the team on what (if anything) we want to change about parsing date time inputs in the csv. It seems better to put it in the backlog for now and think about it more closely once we pivot our focus to revamping bulk upload

Copy link
Collaborator

@mpbrown mpbrown left a comment

Choose a reason for hiding this comment

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

Great job on this! The time zone issues are a real nuisance so I appreciate you working on it!

@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 30, 2024

@mpbrown created a ticket here: #8253

Copy link
Collaborator

@mehansen mehansen left a comment

Choose a reason for hiding this comment

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

lgtm! thoughts on a low-urgency alert of some kind that lets us know if we ever log Unsupported timezone common name? since we don't really have any guarantee that Smarty doesn't change the set of strings they use for that field

@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 31, 2024

lgtm! thoughts on a low-urgency alert of some kind that lets us know if we ever log Unsupported timezone common name? since we don't really have any guarantee that Smarty doesn't change the set of strings they use for that field

I like that idea! Would it be enough for me to create a ticket for it? Or would you like it included in this PR, @mehansen? 🤔

@mehansen
Copy link
Collaborator

lgtm! thoughts on a low-urgency alert of some kind that lets us know if we ever log Unsupported timezone common name? since we don't really have any guarantee that Smarty doesn't change the set of strings they use for that field

I like that idea! Would it be enough for me to create a ticket for it? Or would you like it included in this PR, @mehansen? 🤔

new ticket seems good to me!

@emyl3
Copy link
Collaborator Author

emyl3 commented Oct 31, 2024

lgtm! thoughts on a low-urgency alert of some kind that lets us know if we ever log Unsupported timezone common name? since we don't really have any guarantee that Smarty doesn't change the set of strings they use for that field

I like that idea! Would it be enough for me to create a ticket for it? Or would you like it included in this PR, @mehansen? 🤔

new ticket seems good to me!

@mehansen ticket created here: #8257

@emyl3 emyl3 added this pull request to the merge queue Oct 31, 2024
Merged via the queue into main with commit 7d39218 Oct 31, 2024
37 of 38 checks passed
@emyl3 emyl3 deleted the elisa/8203-PR-timezone-support branch October 31, 2024 20:37
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.

Support Request: User not receiving CSV upload notification (successful or unsuccessful)
4 participants