utcnow

Crates.ioutcnow
lib.rsutcnow
version0.2.6
sourcesrc
created_at2022-07-23 03:27:28.847324
updated_at2024-08-20 09:54:29.929633
descriptionGet the current unixtime in a no-std context
homepage
repositoryhttps://github.com/Kijewski/utcnow
max_upload_size
id631266
size96,653
René Kijewski (Kijewski)

documentation

README

utcnow — Get the current unixtime in a no-std context

GitHub Workflow Status Crates.io Minimum supported Rust version License

This library solves one question, and one question only: What's the time?

In UTC, and according to the clock of the PC, tablet, toaster … the library runs on, expressed as seconds + nanoseconds since 1970-01-01.

let now = utcnow().unwrap();
let seconds = now.as_secs();
let nanos = now.subsec_nanos();

For many target platforms this call cannot fail. If this is true for the current target, then the constant INFALLIBLE will be true.

If the target platform is not supported, then utcnow() will always return an error instead of failing to compile. Use the library with default-features = false and without the feature fallback to get a compile-time error instead.

The feature std (enabled by default) is only needed if you need the Error type to implement std::error::Error.

Supported platforms

If you have successfully tested one of the untested targets, then please tell me. And if not, then even more so!

If you know how to implement another target, then please open a pull request.

Supported and tested:

  • Android
  • Emscripten
  • FreeBSD
  • Haiku
  • Illumos
  • Linux
  • Linux with Musl
  • MacOS
  • NetBSD
  • WASI
  • wasm32
  • Windows

(Probably) supported, but not actually tested:

  • Darwin
  • Dragonfly
  • Fuchsia
  • iOS
  • OpenBSD
  • Redox
  • Solaris

Increasing the msrv for tier-2 or lower platforms will not be indicated as a breaking change to the semver version.

Feature flags

utcnow has the following optional features:

Commit count: 58

cargo fmt