arrow 60.2.0

Rust implementation of Apache Arrow
Documentation
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements

use arrow_cast::parse::string_to_datetime;
use chrono::Utc;

#[test]
fn test_parse_timezone() {
    let cases = [
        (
            "2023-01-01 040506 America/Los_Angeles",
            "2023-01-01T12:05:06+00:00",
        ),
        (
            "2023-01-01 04:05:06.345 America/Los_Angeles",
            "2023-01-01T12:05:06.345+00:00",
        ),
        (
            "2023-01-01 04:05:06.345 America/Los_Angeles",
            "2023-01-01T12:05:06.345+00:00",
        ),
        (
            "2023-01-01 04:05:06.789 -08",
            "2023-01-01T12:05:06.789+00:00",
        ),
        (
            "2023-03-12 040506 America/Los_Angeles",
            "2023-03-12T11:05:06+00:00",
        ), // Daylight savings
        (
            // Sunday, 12 March 2023, 02:00:00 clocks are turned forward 1 hour to
            // Sunday, 12 March 2023, 03:00:00 local daylight time instead, so
            // 02:05:06 never happens. It is shifted forward by the length of the
            // gap, to 03:05:06 PDT, as PostgreSQL and DuckDB do.
            "2023-03-12 02:05:06 America/Los_Angeles",
            "2023-03-12T10:05:06+00:00",
        ),
        (
            // Sunday, 5 November 2023, 02:00:00 clocks are turned backward 1 hour
            // to Sunday, 5 November 2023, 01:00:00 local standard time instead, so
            // 01:30:06 happens twice. The later instant, i.e. PST, is used, as
            // PostgreSQL and DuckDB do.
            "2023-11-05 01:30:06 America/Los_Angeles",
            "2023-11-05T09:30:06+00:00",
        ),
    ];

    for (s, expected) in cases {
        let actual = string_to_datetime(&Utc, s).unwrap().to_rfc3339();
        assert_eq!(actual, expected, "{s}")
    }
}

#[test]
fn test_parse_timezone_invalid() {
    let cases = [
        (
            "2015-01-20T17:35:20-24:00",
            "Parser error: Invalid timezone \"-24:00\": failed to parse timezone",
        ),
        (
            "2023-01-01 04:05:06.789 +07:30:00",
            "Parser error: Invalid timezone \"+07:30:00\": failed to parse timezone",
        ),
    ];

    for (s, expected) in cases {
        let actual = string_to_datetime(&Utc, s).unwrap_err().to_string();
        assert_eq!(actual, expected)
    }
}