Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Update DateType::Date64 docs #6223

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,34 @@ pub enum DataType {
/// A signed 64-bit date representing the elapsed time since UNIX epoch (1970-01-01)
/// in milliseconds.
///
/// According to the specification (see [Schema.fbs]), this should be treated as the number of
/// days, in milliseconds, since the UNIX epoch. Therefore, values must be evenly divisible by
/// `86_400_000` (the number of milliseconds in a standard day).
/// # Valid Ranges
///
/// The reason for this is for compatibility with other language's native libraries,
/// such as Java, which historically lacked a dedicated date type
/// and only supported timestamps.
/// According to the Arrow specification ([Schema.fbs]), values of Date64
/// are treated as the number of *days*, in milliseconds, since the UNIX
/// epoch. Therefore, values of this type must be evenly divisible by
/// `86_400_000`, the number of milliseconds in a standard day.
///
/// Practically, validation that values of this type are evenly divisible by `86_400_000` is not enforced
/// by this library for performance and usability reasons. Date64 values will be treated similarly to the
/// `Timestamp(TimeUnit::Millisecond, None)` type, in that its values will be printed showing the time of
/// day if the value does not represent an exact day, and arithmetic can be done at the millisecond
/// granularity to change the time represented.
/// It is not valid to store milliseconds that do not represent an exact
/// day. The reason for this restriction is compatibility with other
/// language's native libraries (specifically Java), which historically
/// lacked a dedicated date type and only supported timestamps.
///
/// Users should prefer using Date32 to cleanly represent the number of days, or one of the Timestamp
/// variants to include time as part of the representation, depending on their use case.
/// # Validation
///
/// This library does not validate or enforce that Date64 values are evenly
/// divisible by `86_400_000` for performance and usability reasons. Date64
/// values are treated similarly to `Timestamp(TimeUnit::Millisecond,
/// None)`: values will be displayed with a time of day if the value does
/// not represent an exact day, and arithmetic will be done at the
/// millisecond granularity.
///
/// # Recommendation
///
/// Users should prefer [`DataType::Date32`] to cleanly represent the number
/// of days, or one of the Timestamp variants to include time as part of the
/// representation, depending on their use case.
///
/// # Further Reading
///
/// For more details, see [#5288](https://github.com/apache/arrow-rs/issues/5288).
///
Expand Down
Loading