master
Tymon 1 year ago committed by Tymon
parent 625c1fe9aa
commit 81d49c69fe

14
Cargo.lock generated

@ -165,12 +165,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "levenshtein"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.143" version = "0.2.143"
@ -202,7 +196,7 @@ dependencies = [
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"iana-time-zone", "iana-time-zone",
"levenshtein", "strsim",
] ]
[[package]] [[package]]
@ -337,6 +331,12 @@ version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"

@ -9,7 +9,7 @@ edition = "2021"
chrono = "0.4.24" chrono = "0.4.24"
chrono-tz = "0.8.2" chrono-tz = "0.8.2"
iana-time-zone = "0.1.56" iana-time-zone = "0.1.56"
levenshtein = "1.0.5" strsim = "0.10.0"
[lib] [lib]
crate_type = ["cdylib"] crate_type = ["cdylib"]

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

@ -70,7 +70,7 @@ const App: Component = () => {
Invalid time zone specified! Invalid time zone specified!
</Show> </Show>
<Show when={time() !== "INVALID_TIME_ZONE"}> <Show when={time() !== "INVALID_TIME_ZONE"}>
{`It's currently ${time()} in ${timezone()}`} {`It's currently ${time()} in ${timezone().replaceAll("_", " ")}`}
</Show> </Show>
</div> </div>
); );

Loading…
Cancel
Save