Pause#

One split in a task's work: a stretch of elapsed time, measured from the task start, during which the task does no work. A task holds its pauses in TaskData::pauses. Leveling writes them, and you get them back in the task updates of a LevelingResult. Create one with Pause::new or Pause::leveling.

Declaration#

#[derive(Clone, Debug, PartialEq)]
pub struct Pause {
    pub at: f64,
    pub length: f64,
    pub by: Option<PauseSource>,
}

With the serde feature, Pause also implements Serialize and Deserialize. by is left out of the output when it's None and is optional on input.

Fields#

Field Type Description
at f64 Where the pause starts: elapsed time after the task start, in the task's duration_unit. Must be finite and >= 0.
length f64 How long the pause lasts: elapsed time in the task's duration_unit. Must be finite and > 0.
by Option<PauseSource> Who wrote the pause. The leveler always sets Some(PauseSource::Leveling). Default: None.

at and length are wall-clock time, not working time: a day is 24 hours and an hour is 60 minutes. Fractional values are allowed. On use, a pause occupies the whole minutes [round(at), round(at + length)). The two ends are rounded, not at and length separately, so adjacent pauses never overlap after rounding. A pause that rounds to zero length is ignored.

An invalid at or length fails strict validation at tasks[i].pauses[j]; see InputError. The rules for the list as a whole (sorted, non-overlapping) and the task kinds that ignore pauses are on TaskData.

Associated functions#

Pause::new#

pub fn new(at: f64, length: f64) -> Pause

Creates a pause with by: None.

Name Type Description
at f64 Pause start, elapsed time from the task start
length f64 Pause length, elapsed time

Returns a Pause with the given at and length.

Pause::leveling#

pub fn leveling(at: f64, length: f64) -> Pause

Creates a pause the way the leveler writes it: by: Some(PauseSource::Leveling).

Name Type Description
at f64 Pause start, elapsed time from the task start
length f64 Pause length, elapsed time

Returns a Pause with the given at and length and by set to PauseSource::Leveling.

Example#

use plen_core::{Pause, PauseSource, TaskData};

fn main() {
    // With the default day unit: no work from day 2 to day 3 after the start.
    let mut task = TaskData::new(1);
    task.pauses = vec![Pause::leveling(2.0, 1.0)];

    assert_eq!(task.pauses[0].by, Some(PauseSource::Leveling));
    assert_eq!(Pause::new(2.0, 1.0).by, None);
}