ronniskansing / duration-string Goto Github PK
View Code? Open in Web Editor NEWRust - "1ms", "1s", "42m" to Duration and from Duration to string.
Home Page: http://docs.rs/duration-string
License: MIT License
Rust - "1ms", "1s", "42m" to Duration and from Duration to string.
Home Page: http://docs.rs/duration-string
License: MIT License
From edition = "2018"
to edition = "2021"
Implement comparisons with Duration allowing the following:
let duration_string = DurationString::from(Duration::from_secs(1));
let duration = Duration::from_secs(2);
if duration > duration_string {
println!("WOW!")
}
Hi, I realized that if the number of miliseconds is not an exact multiple of seconds, minutes, ..., then it will end generating an string with the default ms
. For example, the following test would fail:
#[test]
fn test_display_trait_2() {
let d = DurationString::try_from(Duration::from_millis(1100));
assert_eq!("1s", format!("{}", d.unwrap()));
}
The fix for that would pass through replacing these lines:
if ms % DAY_IN_MILLI == 0 {
return (ms / DAY_IN_MILLI).to_string() + "d";
}
by
if ms >= DAY_IN_MILLI {
return (ms / DAY_IN_MILLI).to_string() + "d";
}
The following code:
for i in 0..duration.len() {
Is prune to very long input, which could cause an unexpected usage of resources.
It would probably be a good idea to limit how many durations a string may contain.
Set a max iterations and error if stepped over.
µs
is Microsecond
This repo needs some CI that runs test and such
The readme.md needs a update, make it cleaner and better.
Bump the version in the serde example.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.