lofitime
rewrite to use From<T> and Into<T> instead of custom traits
#32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hifitime::Epoch
,hifitime::Duration
,chrono::DateTime<Utc>
, andchrono::Duration
instead of traitshifitime
andchrono
types usingFrom<T>
andInto<T>
Deref
,DerefMut
, andTimelike
forwrapper types
SimpleDateLike
trait for common date operations. (Honestly this is a crutch to avoid making a fullDateLike
implementation for the wrapper type.)Example
Here's an example I'm using to adapt
hifitime::Epoch
s into egui'sDatePickerButton
, which only works withchrono::NaiveDate
s.In this case I don't care about the loss of precision. I want to use the button to select a date and then use this new date as the starting epoch for a precision timer.
hifitime::Epoch
withHifiEpoch
to enable simple type conversions tochrono
types.chrono::NaiveDateTime
with a simple.into()
. This keeps precision up tochrono
's limits, which is in the millisecond range. Note that this is no longer inside a wrapper, it's an actualchrono
type.chrono
type as if it werechrono
all along.chrono::DateTime
withLofiDateTime
to enable simple type conversions back tohifitime
types..into()
to get the datetime back as ahifitime::Epoch
. At this point the epoch only has the precision ofchrono
but from now on we can use it as a precision epoch withhifitime
as if it were an epoch all along.