Skip to content

confused result if ignore the timezone when cast timestamp to the date32 #9982

@liukun4515

Description

@liukun4515

Describe the bug

add other timezone for the timestamp array for test

    fn test_cast_timestamp_to_date32() {
        let array =
            TimestampMillisecondArray::from(vec![Some(864000000005), Some(1545696000001), None])
                .with_timezone("UTC".to_string());
        let b = cast(&array, &DataType::Date32).unwrap();
        let c = b.as_primitive::<Date32Type>();
        assert_eq!(10000, c.value(0));
        assert_eq!(17890, c.value(1));
        assert!(c.is_null(2));

        // cast the timestamp using the different timezone to the date32
        let array =
            TimestampMillisecondArray::from(vec![Some(25201000), Some(111599000), None])
                .with_timezone("-07:00".to_string());

        let b = cast(&array, &DataType::Date32).unwrap();
        let c = b.as_primitive::<Date32Type>();
        println!("{:?}", array);
        println!("{:?}", c);
    }

And will get the result

PrimitiveArray<Timestamp(Millisecond, Some("-07:00"))>
[
  1970-01-01T00:00:01-07:00,
  **1970-01-01T23:59:59-07:00,**
  null,
]
PrimitiveArray<Date32>
[
  1970-01-01,
  **1970-01-02,**
  null,
]

The result is confused

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions