| 662 | } |
| 663 | |
| 664 | static inline bool ParseTimestampISO8601(const char* s, size_t length, |
| 665 | TimeUnit::type unit, TimestampType::c_type* out, |
| 666 | bool* out_zone_offset_present = NULLPTR) { |
| 667 | using seconds_type = std::chrono::duration<TimestampType::c_type>; |
| 668 | |
| 669 | // We allow the following zone offset formats: |
| 670 | // - (none) |
| 671 | // - Z |
| 672 | // - [+-]HH(:?MM)? |
| 673 | // |
| 674 | // We allow the following formats for all units: |
| 675 | // - "YYYY-MM-DD" |
| 676 | // - "YYYY-MM-DD[ T]hhZ?" |
| 677 | // - "YYYY-MM-DD[ T]hh:mmZ?" |
| 678 | // - "YYYY-MM-DD[ T]hh:mm:ssZ?" |
| 679 | // |
| 680 | // We allow the following formats for unit == MILLI, MICRO, or NANO: |
| 681 | // - "YYYY-MM-DD[ T]hh:mm:ss.s{1,3}Z?" |
| 682 | // |
| 683 | // We allow the following formats for unit == MICRO, or NANO: |
| 684 | // - "YYYY-MM-DD[ T]hh:mm:ss.s{4,6}Z?" |
| 685 | // |
| 686 | // We allow the following formats for unit == NANO: |
| 687 | // - "YYYY-MM-DD[ T]hh:mm:ss.s{7,9}Z?" |
| 688 | // |
| 689 | // UTC is always assumed, and the DataType's timezone is ignored. |
| 690 | // |
| 691 | |
| 692 | if (ARROW_PREDICT_FALSE(length < 10)) return false; |
| 693 | |
| 694 | seconds_type seconds_since_epoch; |
| 695 | if (ARROW_PREDICT_FALSE(!ParseYYYY_MM_DD(s, &seconds_since_epoch))) { |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | if (length == 10) { |
| 700 | return util::CastSecondsToUnit(unit, seconds_since_epoch.count(), out); |
| 701 | } |
| 702 | |
| 703 | if (ARROW_PREDICT_FALSE(s[10] != ' ') && ARROW_PREDICT_FALSE(s[10] != 'T')) { |
| 704 | return false; |
| 705 | } |
| 706 | |
| 707 | if (out_zone_offset_present) { |
| 708 | *out_zone_offset_present = false; |
| 709 | } |
| 710 | |
| 711 | seconds_type zone_offset(0); |
| 712 | if (s[length - 1] == 'Z') { |
| 713 | --length; |
| 714 | if (out_zone_offset_present) *out_zone_offset_present = true; |
| 715 | } else if (s[length - 3] == '+' || s[length - 3] == '-') { |
| 716 | // [+-]HH |
| 717 | length -= 3; |
| 718 | if (ARROW_PREDICT_FALSE(!detail::ParseHH(s + length + 1, &zone_offset))) { |
| 719 | return false; |
| 720 | } |
| 721 | if (s[length] == '+') zone_offset *= -1; |