Skip to content

Commit

Permalink
lofitime rewrite to use From<T> and Into<T> instead of custom traits (
Browse files Browse the repository at this point in the history
#32)

* lofitime: total rewrite from traits to From

* lofitime: total rewrite using From impls
  • Loading branch information
philiplinden authored Sep 4, 2024
1 parent ce3eee8 commit 15eff60
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lofitime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lofitime"
description = "Handy translations between Hifitime and Chrono datetimes and durations."
version = "0.1.0"
version = "0.2.0"
authors.workspace = true
edition.workspace = true

Expand Down
49 changes: 49 additions & 0 deletions lofitime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# lofitime

`lofitime` is a Rust crate that provides wrapper types and conversion utilities
for working with both high-precision (`hifitime`) and low-precision (`chrono`)
time libraries. This crate aims to bridge the gap between these two popular
time-handling libraries in the Rust ecosystem.

## Features

- Wrapper types for `hifitime::Epoch`, `hifitime::Duration`,
`chrono::DateTime<Utc>`, and `chrono::Duration`
- Low-friction conversions between `hifitime` and `chrono` types
- Implementation of common traits like `Deref`, `DerefMut`, and `Timelike` for
wrapper types
- Simplified `SimpleDateLike` trait for common date operations

## Todos
- [ ] ✨Seamless✨ conversions between `hifitime` and `chrono` types
- [ ] Upstream into `hifitime`?

## Usage

Add this to your `Cargo.toml`:

```toml
[dependencies]
lofitime = "0.2.0"
```

Then, you can use the wrapper types in your code:

```rust
use lofitime::{HifiEpoch, LofiDateTime};

let hifi_epoch = HifiEpoch(hifitime::Epoch::from_gregorian_utc(2023, 8, 12, 15, 30, 45, 0));
let lofi_datetime: LofiDateTime = hifi_epoch.into();

assert_eq!(lofi_datetime.year(), 2023);
assert_eq!(lofi_datetime.month(), 8);
assert_eq!(lofi_datetime.day(), 12);
```

## Why use lofitime?

- **Interoperability**: Easily convert between `hifitime` and `chrono` types.
- **Simplified API**: Use a consistent interface for both high-precision and
low-precision time operations.
- **Type Safety**: Wrapper types provide clear distinctions between different
time representations.
Loading

0 comments on commit 15eff60

Please sign in to comment.