|
|
|
@ -3,7 +3,7 @@ use std::ffi::{c_char, c_double, CStr, CString};
|
|
|
|
|
use chrono::Local;
|
|
|
|
|
use chrono_tz::{Tz, TZ_VARIANTS};
|
|
|
|
|
|
|
|
|
|
use levenshtein::levenshtein;
|
|
|
|
|
use strsim::levenshtein;
|
|
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub extern "C" fn id() -> *const c_char {
|
|
|
|
@ -32,10 +32,10 @@ pub extern "C" fn get_priority(data: *const c_char) -> c_double {
|
|
|
|
|
#[no_mangle]
|
|
|
|
|
pub extern "C" fn get_timezone_name(data: *const c_char) -> *const c_char {
|
|
|
|
|
let data = ptr_to_string(data);
|
|
|
|
|
let local_time = iana_time_zone::get_timezone().unwrap_or_default();
|
|
|
|
|
let local_timezone = iana_time_zone::get_timezone().unwrap_or_default();
|
|
|
|
|
|
|
|
|
|
if data == "" {
|
|
|
|
|
return str_to_ptr(&local_time);
|
|
|
|
|
return str_to_ptr(&local_timezone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(timezone) = get_closest_zone(data) {
|
|
|
|
@ -77,12 +77,13 @@ fn get_closest_zone(zone: String) -> Option<Tz> {
|
|
|
|
|
&zone.to_string().to_lowercase(),
|
|
|
|
|
&variant.to_string().to_lowercase(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if variant_distance < closest_distance {
|
|
|
|
|
closest_distance = variant_distance;
|
|
|
|
|
closest_zone = Some(variant);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
closest_zone
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|