Skip to content

uefi: Add integration with crates jiff and time for struct Time#1911

Open
phip1611 wants to merge 9 commits intomainfrom
uefi-raw-time-v3
Open

uefi: Add integration with crates jiff and time for struct Time#1911
phip1611 wants to merge 9 commits intomainfrom
uefi-raw-time-v3

Conversation

@phip1611
Copy link
Copy Markdown
Member

This is my third design, superseding the outdated approaches #1896 and #1899.

Motivation

My high-level goal is to make struct Time more useable, e.g., compare dates (before, after, ...).

Design

This PR integrates struct Time of the uefi crate with https://crates.io/crates/time and https://crates.io/crates/jiff. I decided for the following design:

  • TryFrom and no specific constructors
  • Use the "datetime without timezone" and "datetime with timezone" types of the time libraries

Error

There is a single opaque ConversionError shared by all TryFrom impls.

Implementation

  • time crate

    • struct Time <--> PrimitiveDateTime (without timezone)
    • struct Time <--> OffsetDateTime (with timezone)
  • jiff crate

    • struct Time <--> DateTime (without timezone)
    • struct Time <--> Zoned (with timezone)

@phip1611
Copy link
Copy Markdown
Member Author

@nicholasbishop thanks for your valuable review and feedback in #1896 and #1899. I think we are now the closest to have something useful and mergable. Looking forward to your feedback!

This is a preparation to integrate the popular time-related crates
`jiff` and `time` with `struct Time` of the `uefi` crate.
I split the time-related type definitions from the time-related runtime
UEFI services.

This is a preparation to integrate the popular time-related crates
`jiff` and `time` with `struct Time` of the `uefi` crate.
This module provides the foundational plumbing for future time-related
crate integrations. It introduces common error types, including a
unified opaque ConversionError to standardize conversion failures across
crates.

While integration with crates like time and jiff is planned in
subsequent commits, this module lays the groundwork, ensuring a
consistent and minimal API for handling errors once those integrations
are implemented.
This allows to pass `jiff::{DateTime, Zoned}` and
`time::{PrimitiveDateTime,OffsetDateTime}`.
Copy link
Copy Markdown
Member

@nicholasbishop nicholasbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, but I haven't reviewed in detail yet. Let's break it apart some. I think start with a new PR to move the Time stuff to a new module like uefi::runtime::time, then a PR to add time, then jiff.

Comment thread uefi/src/runtime/mod.rs
/// Undefined behavior could happen if multiple tasks try to
/// use this function at the same time without synchronisation.
pub unsafe fn set_time(time: &Time) -> Result {
pub unsafe fn set_time<T: Clone + TryInto<Time>>(time: &T) -> Result {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to revert this change. Time conversion is fraught enough that keeping it explicit seems worthwhile to me, especially since set_time is unlikely to be called frequently in code so implicit conversion probably isn't doing much to make calling code more readable.

Comment thread uefi/src/runtime/mod.rs
//! functions after exiting boot services; see the "Calling Convention" section
//! of the UEFI specification for details.

mod time_defs;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: module could be called just time, I don't think defs is adding any clarity.

Comment thread uefi/src/runtime/mod.rs
Ok(())
}

/// Date and time representation.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this move of Time stuff to a new module in its own PR and merge that first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants