generated from PlexSheep/rs-base
support H:M format in countdown
This commit is contained in:
parent
12150375cb
commit
f3e58a635d
2 changed files with 10 additions and 3 deletions
|
@ -272,6 +272,12 @@ fn parse_datetime(s: &str) -> Result<DateTime<Local>, String> {
|
|||
let s = s.trim();
|
||||
let today = Local::today();
|
||||
|
||||
let time = NaiveTime::parse_from_str(s, "%H:%M");
|
||||
if time.is_ok() {
|
||||
let time = NaiveDateTime::new(today.naive_local(), time.unwrap());
|
||||
return Ok(Local.from_local_datetime(&time).unwrap());
|
||||
}
|
||||
|
||||
let time = NaiveTime::parse_from_str(s, "%H:%M:%S");
|
||||
if time.is_ok() {
|
||||
let time = NaiveDateTime::new(today.naive_local(), time.unwrap());
|
||||
|
|
|
@ -47,9 +47,6 @@ fn format_duration(duration: Duration, format: DurationFormat) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
if is_neg {
|
||||
result.push('-');
|
||||
}
|
||||
if days > 0 {
|
||||
let _ = write!(result, "{}:", days);
|
||||
}
|
||||
|
@ -59,6 +56,10 @@ fn format_duration(duration: Duration, format: DurationFormat) -> String {
|
|||
}
|
||||
append_number(&mut result, minutes % 60);
|
||||
result.push(':');
|
||||
|
||||
if is_neg {
|
||||
result.insert(0, '-');
|
||||
}
|
||||
match format {
|
||||
DurationFormat::HourMinSecDeci => {
|
||||
let _ = write!(result, "{:02}.{}", seconds % 60, (millis % 1000) / 100);
|
||||
|
|
Reference in a new issue