1
2
3
4
5
6
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
use alloc::string::{ToString, String};
use crate::config::SmartCalcConfig;
pub fn do_divition(left: f64, right: f64) -> f64 {
let mut calculation = left / right;
if calculation.is_infinite() || calculation.is_nan() {
calculation = 0.0;
}
calculation
}
pub fn parse_timezone<'t>(config: &SmartCalcConfig, capture: ®ex::Captures<'t>) -> Option<(String, i32)> {
match capture.name("timezone_1") {
Some(tz) => {
let timezone = tz.as_str().to_uppercase();
match config.timezones.get(&timezone) {
Some(offset) => Some((timezone, *offset)),
None => None
}
},
None => match capture.name("timezone_2") {
Some(tz) => {
let hour = capture.name("timezone_hour").unwrap().as_str().parse::<i32>().unwrap();
let minute = match capture.name("timezone_minute") {
Some(minute) => {
minute.as_str().parse::<i32>().unwrap()
},
_ => 0
};
let timezone_type = match capture.name("timezone_type") {
Some(timezone_type) => match timezone_type.as_str() {
"-" => -1,
_ => 1
},
None => 1
};
Some((tz.as_str().to_string(), (hour * 60 + minute) * timezone_type))
},
None => None
}
}
}