-
Notifications
You must be signed in to change notification settings - Fork 54
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,33 @@ 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
if Now, since we are using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: single entry flow |
||
|
||
public static final Map<String, ZoneId> validTimeZoneIdMap = | ||
/** | ||
* 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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strange that they use this list instead of something more standard |
||
Map.ofEntries( | ||
Map.entry("Alaska".toLowerCase(), alaskaTimeZoneId), | ||
Map.entry("Atlantic".toLowerCase(), puertoRicoTimeZoneId), | ||
Map.entry("Central".toLowerCase(), centralTimeZoneId), | ||
Map.entry("Eastern".toLowerCase(), easternTimeZoneId), | ||
Map.entry("Hawaii".toLowerCase(), hawaiiTimeZoneId), | ||
Map.entry("Mountain".toLowerCase(), mountainTimeZoneId), | ||
Map.entry("None".toLowerCase(), FALLBACK_TIMEZONE_ID), | ||
Map.entry("Pacific".toLowerCase(), pacificTimeZoneId), | ||
Map.entry("Samoa".toLowerCase(), samoaTimeZoneId), | ||
Map.entry("UTC+9".toLowerCase(), ZoneId.of("+9")), | ||
Map.entry("UTC+10".toLowerCase(), ZoneId.of("+10")), | ||
Map.entry("UTC+11".toLowerCase(), ZoneId.of("+11")), | ||
Map.entry("UTC+12".toLowerCase(), ZoneId.of("+12"))); | ||
|
||
/** | ||
* 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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Map.ofEntries( | ||
Map.entry("UTC", ZoneOffset.UTC), | ||
Map.entry("UT", ZoneOffset.UTC), | ||
|
@@ -64,7 +89,9 @@ public class DateTimeUtils { | |
Map.entry("HDT", aleutianTimeZoneId), | ||
Map.entry("AS", samoaTimeZoneId), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOO thank you for letting me know! I'll take a look! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added "AS" and "ASM" back |
||
Map.entry("ASM", samoaTimeZoneId), | ||
Map.entry("SST", samoaTimeZoneId)); | ||
Map.entry("SST", samoaTimeZoneId), | ||
Map.entry("ADT", puertoRicoTimeZoneId), | ||
Map.entry("AST", puertoRicoTimeZoneId)); | ||
|
||
public static ZonedDateTime convertToZonedDateTime( | ||
String dateString, | ||
|
@@ -111,8 +138,8 @@ public static boolean hasTimezoneSubstring(String value) { | |
} | ||
|
||
public static ZoneId parseZoneId(String timezoneCode) { | ||
if (validTimeZoneIdMap.containsKey(timezoneCode.toUpperCase())) { | ||
return validTimeZoneIdMap.get(timezoneCode.toUpperCase()); | ||
if (timezoneAbbreviationZoneIdMap.containsKey(timezoneCode.toUpperCase())) { | ||
return timezoneAbbreviationZoneIdMap.get(timezoneCode.toUpperCase()); | ||
} | ||
return ZoneId.of(timezoneCode); | ||
} | ||
|
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.
Atlantic
fortimezoneInfo.timezoneCommonName
.If you see the list here,
US/Atlantic
doesn't exist and was throwing an exception.Decided to get the
ZoneId
using theZoneOffset
value instead.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.
I think using the
ZoneOffset
might run into issues with whetherZoneId.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 existingUS/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 withutcOffset
? I wish Smartystreets simply returned the official time zone rather than just the common name 😩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.
OOO thank you for this context, Mike! I will rethink my implementation!