Function yonsei_flexible::calc::calc_work_time
source · Examples found in repository?
examples/example.rs (line 48)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() {
let example_inputs = r#"
10:00:00 - 17:00:00
10:00:00 - 21:00:00
11:15:00 - 17:00:00
11:45:00 - 17:00:00
12:15:00 - 17:00:00
12:45:00 - 17:00:00
11:15:00 - 18:15:00
11:45:00 - 18:15:00
12:15:00 - 18:15:00
12:45:00 - 18:15:00
11:15:00 - 18:45:00
11:45:00 - 18:45:00
12:15:00 - 18:45:00
12:45:00 - 18:45:00
11:15:00 - 19:15:00
11:45:00 - 19:15:00
12:15:00 - 19:15:00
12:45:00 - 19:15:00
11:15:00 - 19:45:00
11:45:00 - 19:45:00
12:15:00 - 19:45:00
12:45:00 - 19:45:00
"#;
let inputs = example_inputs
.lines()
.filter(|line| !line.trim().is_empty())
.map(|line| {
let mut iter = line.split("-");
let start = iter.next().unwrap().trim();
let end = iter.next().unwrap().trim();
Interval::new(HMS::parse(start).unwrap(), HMS::parse(end).unwrap())
})
.collect::<Vec<_>>();
for input in inputs {
println!("==================================================");
println!("Input: {} - {}", input.start_time, input.end_time);
println!("Total time: {}", input.get_duration());
println!("Work time: {}", calc_work_time(input));
println!("==================================================");
println!("");
}
}
More examples
src/calc.rs (line 32)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
pub fn calc_hope_finish_time(start: HMS, hope_work_time: HMS) -> HMS {
let mut finish = start + hope_work_time;
let mut work_time = calc_work_time(Interval::new(start, finish));
loop {
if work_time < hope_work_time {
finish = finish + (hope_work_time - work_time);
work_time = calc_work_time(Interval::new(start, finish));
} else if work_time > hope_work_time {
finish = finish - (work_time - hope_work_time);
work_time = calc_work_time(Interval::new(start, finish));
} else {
break;
}
}
finish
}