Skip to content

Add some way to create a Timestamp from a DateTime #9337

@alamb

Description

@alamb

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
In DataFusion we have occasions where we have a chrono NiaveDateTime or DateTime and would like to create the corresponding Timestamp value (e.g. i64)

This came up recently in https://github.com/apache/datafusion/pull/19733/changes#r2742968186\\

Basically we want the API

fn date_to_scalar(date: NaiveDate, target_type: &DataType) -> Option<ScalarValue> {

We have Date32Type::from_naive_date(date) but couldn't find the equivalent of Timestamp types as well

I was hoping for something like TimestampSecondType::from_datetime or something but all I could find was

https://docs.rs/arrow/latest/arrow/array/types/struct.TimestampSecondType.html and https://docs.rs/arrow/latest/arrow/datatypes/trait.ArrowTimestampType.html

Instead we went with our own date/time parsing (see apache/datafusion#19733)

Describe the solution you'd like
Add an API so downstream crates can avoid having to do date/time/timestamp arithmetic to convert from a NiaveDate (or document the conversion better)

Describe alternatives you've considered

Additional context

Metadata

Metadata

Assignees

Labels

enhancementAny new improvement worthy of a entry in the changelog

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions