time: rustfmt

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-10 12:33:56 +02:00
parent 800cf63a8a
commit 4554034d32
7 changed files with 24 additions and 29 deletions

View File

@ -37,7 +37,7 @@ pub struct CalendarEvent {
pub(crate) year: Vec<DateTimeValue>, pub(crate) year: Vec<DateTimeValue>,
} }
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
impl CalendarEvent { impl CalendarEvent {
/// Computes the next timestamp after `last`. If `utc` is false, the local /// Computes the next timestamp after `last`. If `utc` is false, the local
/// timezone will be used for the calculation. /// timezone will be used for the calculation.
@ -181,8 +181,8 @@ pub fn verify_calendar_event(i: &str) -> Result<(), Error> {
} }
/// Compute the next event. Use [CalendarEvent::compute_next_event] instead. /// Compute the next event. Use [CalendarEvent::compute_next_event] instead.
#[deprecated="use method 'compute_next_event' of CalendarEvent instead"] #[deprecated = "use method 'compute_next_event' of CalendarEvent instead"]
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn compute_next_event( pub fn compute_next_event(
event: &CalendarEvent, event: &CalendarEvent,
last: i64, last: i64,
@ -197,7 +197,7 @@ pub fn compute_next_event(
} }
/// Parse a [CalendarEvent] /// Parse a [CalendarEvent]
#[deprecated="use std::str::FromStr trait instead"] #[deprecated = "use std::str::FromStr trait instead"]
pub fn parse_calendar_event(i: &str) -> Result<CalendarEvent, Error> { pub fn parse_calendar_event(i: &str) -> Result<CalendarEvent, Error> {
i.parse() i.parse()
} }

View File

@ -3,19 +3,16 @@ use std::convert::{TryFrom, TryInto};
use anyhow::Error; use anyhow::Error;
use nom::{ use nom::{
bytes::complete::tag, bytes::complete::tag, character::complete::space0, error::context,
character::complete::space0,
error::context,
multi::separated_nonempty_list, multi::separated_nonempty_list,
}; };
use crate::parse_helpers::{parse_complete_line, parse_error, parse_hm_time, IResult}; use crate::parse_helpers::{parse_complete_line, parse_error, parse_hm_time, IResult};
use crate::{parse_weekdays_range, WeekDays}; use crate::{parse_weekdays_range, WeekDays};
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use crate::TmEditor; use crate::TmEditor;
/// Time of Day (hour with minute) /// Time of Day (hour with minute)
#[derive(Default, PartialEq, Clone, Debug)] #[derive(Default, PartialEq, Clone, Debug)]
pub struct HmTime { pub struct HmTime {
@ -42,7 +39,7 @@ pub struct DailyDuration {
pub end: HmTime, pub end: HmTime,
} }
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
impl DailyDuration { impl DailyDuration {
/// Test it time is within this frame /// Test it time is within this frame
pub fn time_match(&self, epoch: i64, utc: bool) -> Result<bool, Error> { pub fn time_match(&self, epoch: i64, utc: bool) -> Result<bool, Error> {

View File

@ -40,7 +40,9 @@ impl DateTimeValue {
let mut next: Option<u32> = None; let mut next: Option<u32> = None;
let mut set_next = |v: u32| { let mut set_next = |v: u32| {
if let Some(n) = next { if let Some(n) = next {
if v < n { next = Some(v); } if v < n {
next = Some(v);
}
} else { } else {
next = Some(v); next = Some(v);
} }
@ -48,7 +50,9 @@ impl DateTimeValue {
for spec in list { for spec in list {
match spec { match spec {
DateTimeValue::Single(v) => { DateTimeValue::Single(v) => {
if *v > value { set_next(*v); } if *v > value {
set_next(*v);
}
} }
DateTimeValue::Range(start, end) => { DateTimeValue::Range(start, end) => {
if value < *start { if value < *start {

View File

@ -1,8 +1,8 @@
#![allow(clippy::manual_range_contains)] #![allow(clippy::manual_range_contains)]
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
mod tm_editor; mod tm_editor;
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use tm_editor::*; pub use tm_editor::*;
pub(crate) mod parse_helpers; pub(crate) mod parse_helpers;
@ -21,14 +21,14 @@ pub use week_days::*;
mod daily_duration; mod daily_duration;
pub use daily_duration::*; pub use daily_duration::*;
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
mod posix; mod posix;
#[cfg(not(target_arch="wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use posix::*; pub use posix::*;
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
mod wasm; mod wasm;
#[cfg(target_arch="wasm32")] #[cfg(target_arch = "wasm32")]
pub use wasm::*; pub use wasm::*;
#[cfg(test)] #[cfg(test)]

View File

@ -207,7 +207,7 @@ impl std::str::FromStr for TimeSpan {
} }
/// Parse a [TimeSpan] /// Parse a [TimeSpan]
#[deprecated="Use std::str::FromStr trait instead."] #[deprecated = "Use std::str::FromStr trait instead."]
pub fn parse_time_span(i: &str) -> Result<TimeSpan, Error> { pub fn parse_time_span(i: &str) -> Result<TimeSpan, Error> {
i.parse() i.parse()
} }
@ -271,4 +271,3 @@ pub fn verify_time_span(i: &str) -> Result<(), Error> {
let _: TimeSpan = i.parse()?; let _: TimeSpan = i.parse()?;
Ok(()) Ok(())
} }

View File

@ -10,18 +10,18 @@ pub fn epoch_f64() -> f64 {
js_sys::Date::now() / 1000.0 js_sys::Date::now() / 1000.0
} }
/// Convert Unix epoch into RFC3339 local time with TZ /// Convert Unix epoch into RFC3339 local time with TZ
pub fn epoch_to_rfc3339(epoch: i64) -> Result<String, Error> { pub fn epoch_to_rfc3339(epoch: i64) -> Result<String, Error> {
let js_date = js_sys::Date::new_0(); let js_date = js_sys::Date::new_0();
js_date.set_time((epoch as f64) * 1000.0); js_date.set_time((epoch as f64) * 1000.0);
js_date.to_iso_string().as_string() js_date
.to_iso_string()
.as_string()
.ok_or_else(|| format_err!("to_iso_string did not return a string")) .ok_or_else(|| format_err!("to_iso_string did not return a string"))
} }
/// Parse RFC3339 into Unix epoch /// Parse RFC3339 into Unix epoch
pub fn parse_rfc3339(input_str: &str) -> Result<i64, Error> { pub fn parse_rfc3339(input_str: &str) -> Result<i64, Error> {
// TOTO: This should parse olny RFC3339, but currently also parse // TOTO: This should parse olny RFC3339, but currently also parse
// other formats // other formats
let time_milli = js_sys::Date::parse(input_str); let time_milli = js_sys::Date::parse(input_str);

View File

@ -1,10 +1,5 @@
use bitflags::bitflags; use bitflags::bitflags;
use nom::{ use nom::{bytes::complete::tag, character::complete::alpha1, combinator::opt, sequence::pair};
bytes::complete::tag,
character::complete::alpha1,
combinator::opt,
sequence::pair,
};
use crate::parse_helpers::{parse_error, IResult}; use crate::parse_helpers::{parse_error, IResult};