Joda only supports parsing a few three-letter prefixes. The list is available here: https://github.com/JodaOrg/joda-time/blob/main/src/main/java/org/joda/time/DateTimeUtils.java#L437 Full timezone names (e.g. "America/Los_Angeles") are not supported by Joda when parsing, so we don't implement them here.
| 329 | // Full timezone names (e.g. "America/Los_Angeles") are not supported by Joda |
| 330 | // when parsing, so we don't implement them here. |
| 331 | int64_t parseTimezone( |
| 332 | const char* cur, |
| 333 | const char* end, |
| 334 | Date& date, |
| 335 | bool legacySpark = false) { |
| 336 | if (cur < end) { |
| 337 | // If there are at least 3 letters left. |
| 338 | if (end - cur >= 3) { |
| 339 | static std::unordered_map<std::string_view, int64_t> defaultTzNames{ |
| 340 | {"UTC", 0}, |
| 341 | {"GMT", 0}, |
| 342 | {"EST", tz::getTimeZoneID("America/New_York")}, |
| 343 | {"EDT", tz::getTimeZoneID("America/New_York")}, |
| 344 | {"CST", tz::getTimeZoneID("America/Chicago")}, |
| 345 | {"CDT", tz::getTimeZoneID("America/Chicago")}, |
| 346 | {"MST", tz::getTimeZoneID("America/Denver")}, |
| 347 | {"MDT", tz::getTimeZoneID("America/Denver")}, |
| 348 | {"PST", tz::getTimeZoneID("America/Los_Angeles")}, |
| 349 | {"PDT", tz::getTimeZoneID("America/Los_Angeles")}, |
| 350 | }; |
| 351 | std::string_view zone(cur, 3); |
| 352 | #ifdef SPARK_COMPATIBLE |
| 353 | // spark accept timezone in lower case |
| 354 | std::string upper; |
| 355 | for (auto& c : zone) { |
| 356 | upper.push_back(toupper(c)); |
| 357 | } |
| 358 | zone = upper; |
| 359 | #endif |
| 360 | auto it = defaultTzNames.find(zone); |
| 361 | if (it != defaultTzNames.end()) { |
| 362 | date.timezoneId = it->second; |
| 363 | return 3; |
| 364 | } |
| 365 | } |
| 366 | #ifndef SPARK_COMPATIBLE |
| 367 | // The format 'UT' is also accepted for UTC. |
| 368 | else if ((end - cur == 2) && (*cur == 'U') && (*(cur + 1) == 'T')) { |
| 369 | date.timezoneId = 0; |
| 370 | return 2; |
| 371 | } |
| 372 | #else |
| 373 | if ((*cur == '+') || (*cur == '-')) { |
| 374 | int64_t timezoneId = -1; |
| 375 | int64_t length = 0; |
| 376 | if (legacySpark && (end - cur) >= 5) { |
| 377 | // spark LEGACY accept (+/-)HHMM as time zone |
| 378 | std::string tz = std::string(cur, 3) + ":" + std::string(cur + 3, 2); |
| 379 | timezoneId = tz::getTimeZoneID(tz, false); |
| 380 | length = 5; |
| 381 | } else if (!legacySpark && (end - cur) >= 6 && *(cur + 3) == ':') { |
| 382 | // spark CORRECTED accept (+/-)HH:MM as time zone |
| 383 | timezoneId = tz::getTimeZoneID(std::string_view(cur, 6), false); |
| 384 | length = 6; |
| 385 | } |
| 386 | if (timezoneId != -1) { |
| 387 | date.timezoneId = timezoneId; |
| 388 | return length; |
no test coverage detected