generated from PlexSheep/rs-base
fix: crashed when no timebar was requested because we unwrapped for the creation of Ui Data #26
cargo devel CI / cargo CI (push) Has been cancelled
Details
cargo devel CI / cargo CI (push) Has been cancelled
Details
This commit is contained in:
parent
04c570243c
commit
140123c124
|
@ -222,7 +222,7 @@ impl Clock {
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let tick_rate = std::time::Duration::from_millis(100);
|
let tick_rate = std::time::Duration::from_millis(100);
|
||||||
let mut last_tick = Instant::now();
|
let mut last_tick = Instant::now();
|
||||||
let mut uidata: Data = Data::new(self.timebar_len().unwrap());
|
let mut uidata: Data = Data::new(self.timebar_len());
|
||||||
self.setup()?;
|
self.setup()?;
|
||||||
loop {
|
loop {
|
||||||
let raw_time = chrono::Local::now().round_subsecs(0);
|
let raw_time = chrono::Local::now().round_subsecs(0);
|
||||||
|
|
|
@ -19,14 +19,14 @@ pub struct Data {
|
||||||
ftime: [String; 2],
|
ftime: [String; 2],
|
||||||
timebar_ratio: [Option<f64>; 2],
|
timebar_ratio: [Option<f64>; 2],
|
||||||
|
|
||||||
timebar_type: TimeBarLength,
|
timebar_type: Option<TimeBarLength>,
|
||||||
started_at: DateTime<Local>,
|
started_at: DateTime<Local>,
|
||||||
|
|
||||||
idx: usize,
|
idx: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
pub fn new(timebar_type: TimeBarLength) -> Self {
|
pub fn new(timebar_type: Option<TimeBarLength>) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
now: [DateTime::default(); 2],
|
now: [DateTime::default(); 2],
|
||||||
fdate: [String::new(), String::new()],
|
fdate: [String::new(), String::new()],
|
||||||
|
@ -91,7 +91,7 @@ impl Data {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(clippy::missing_const_for_fn)] // no it's not const
|
#[allow(clippy::missing_const_for_fn)] // no it's not const
|
||||||
pub fn timebar_ratio(&self) -> Option<f64> {
|
pub fn timebar_ratio(&self) -> Option<f64> {
|
||||||
if self.timebar_type == TimeBarLength::Timer {
|
if self.timebar_type.is_some() && self.timebar_type.unwrap() == TimeBarLength::Timer {
|
||||||
return Some(0.0);
|
return Some(0.0);
|
||||||
}
|
}
|
||||||
self.timebar_ratio[self.idx]
|
self.timebar_ratio[self.idx]
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn mock_tests() {
|
||||||
info!("0s=0.0");
|
info!("0s=0.0");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut data = Data::new(clock::timebar::TimeBarLength::Day);
|
let mut data = Data::new(None);
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1));
|
data.update(now, "date".to_owned(), "time".to_owned(), Some(0.1));
|
||||||
assert_eq!(data.timebar_ratio(), Some(0.1));
|
assert_eq!(data.timebar_ratio(), Some(0.1));
|
||||||
|
|
Reference in New Issue