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

Use raw u64 instead of chrono on RTC API #3200

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

robertbastian
Copy link

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

#3185

Testing

@bugadani
Copy link
Contributor

bugadani commented Mar 3, 2025

Why isn't our own time::Instant good here?

@robertbastian
Copy link
Author

I assume because that's not using the UNIX epoch.

@bugadani
Copy link
Contributor

bugadani commented Mar 3, 2025

Neither does the hardware. We can redefine Instant to have an undefined epoch, we can state that now() returns time since boot, and RTC has a user settable 0 by set_current_time, it'd all be mostly just documentation change.

@robertbastian
Copy link
Author

Well I don't know what to tell you, I advocated for dumb types in #3185, but @MabezDev wanted this to be a proper datetime type.

esp_hal::time::Instant uses boot time, we should not start creating them with UNIX time here. It should not be possible to use a UNIX timestamp where a boot timestamp is expected, and vice versa.

jiff::Timestamp is an improvement over chrono::NaiveDateTime.

@MabezDev
Copy link
Member

MabezDev commented Mar 4, 2025

Well I don't know what to tell you, I advocated for dumb types in #3185, but @MabezDev wanted this to be a proper datetime type.

I think the suggestion here to add jiff as a dev dep and create a doc example is a nice compromise. I'd be happy to have a dumb type API provided it has a example that shows how to use it with some time library. Please note that the timer we use can't do nanosecond precision, only microsecond.

I think the following comment is also correct, it should return a u64.

@robertbastian robertbastian changed the title Use jiff instead of chrono Use raw u64 instead of chrono on RTC API Mar 4, 2025
Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Just need to sort CI out now, don't worry about the MSRV check, we need to resolve that seperately.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM

@robertbastian
Copy link
Author

Is there a way to actually obtain an Rtc in an docs test? The existing examples are no_run.

@robertbastian
Copy link
Author

Jiff is annoying to use here because no-alloc time zone support is limited. I could remove the example using the time zone, or rewrite it using chrono.

@MabezDev
Copy link
Member

MabezDev commented Mar 4, 2025

Jiff is annoying to use here because no-alloc time zone support is limited. I could remove the example using the time zone, or rewrite it using chrono.

I'd prefer without alloc, if we can get away with it. Is it possible to bundle some time zones statically at compile time?

@BurntSushi
Copy link

It will be in the next Jiff release. Maybe this week. The functionality (via a proc macro) is on master, but I have some polishing to do before it's released.

@robertbastian
Copy link
Author

I have removed the examples because I cannot get them to work. Feel free to add them yourselves if you have a faster test cycle than waiting for CI, or know how exactly to set them up.

@robertbastian robertbastian requested a review from MabezDev March 5, 2025 00:55
@bugadani
Copy link
Contributor

bugadani commented Mar 5, 2025

I have removed the examples because I cannot get them to work

You should be able to run cargo xtask run-doc-tests esp-hal esp32c3 locally

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.

5 participants