| 20 | namespace arrow::compute::internal { |
| 21 | |
| 22 | Result<ArrowTimeZone> LocateZone(const std::string_view timezone) { |
| 23 | if (timezone[0] == '+' || timezone[0] == '-') { |
| 24 | // Valid offset strings have to have 4 digits and a sign prefix. |
| 25 | // Valid examples: +01:23 and -0123. |
| 26 | // Invalid examples: 1:23, 123, 0123, 01:23, +25:00, -12:34:45, +090000. |
| 27 | auto offset = std::string(timezone.substr(1)); |
| 28 | std::chrono::minutes zone_offset; |
| 29 | switch (timezone.length()) { |
| 30 | case 6: |
| 31 | if (arrow::internal::detail::ParseHH_MM(offset.c_str(), &zone_offset)) { |
| 32 | break; |
| 33 | } |
| 34 | [[fallthrough]]; |
| 35 | case 5: |
| 36 | if (arrow::internal::detail::ParseHHMM(offset.c_str(), &zone_offset)) { |
| 37 | break; |
| 38 | } |
| 39 | [[fallthrough]]; |
| 40 | default: |
| 41 | return Status::Invalid("Cannot locate or parse timezone '", timezone, "'"); |
| 42 | } |
| 43 | zone_offset = timezone[0] == '-' ? -zone_offset : zone_offset; |
| 44 | return OffsetZone(zone_offset); |
| 45 | } |
| 46 | |
| 47 | try { |
| 48 | return locate_zone(timezone); |
| 49 | } catch (const std::runtime_error& ex) { |
| 50 | return Status::Invalid("Cannot locate or parse timezone '", timezone, |
| 51 | "': ", ex.what()); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | } // namespace arrow::compute::internal |
nothing calls this directly
no test coverage detected