-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimezone.rs
40 lines (36 loc) · 1.3 KB
/
timezone.rs
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
fn main() {
// Create a new client.
let mut abstractapi = abstractapi::AbstractApi::default();
abstractapi
.set_api_key(
abstractapi::ApiType::Timezone,
std::env::var("TIMEZONE_API_KEY").unwrap(),
)
.unwrap();
// Define a closure for printing the results in pretty format.
let print_pretty = |description: &str, time: abstractapi::api::timezone::LocationTime| {
println!(
"{}: {}, Timezone: {}, Location: {} (long: {} lat: {})",
description,
time.datetime,
time.timezone_name,
time.requested_location,
time.longitude,
time.latitude,
);
};
// Get the current time in Ankara, Turkey.
let current_time = abstractapi.get_current_time("Ankara").unwrap();
print_pretty("Current time", current_time);
std::thread::sleep(std::time::Duration::from_secs(1));
// Convert time using base and target locations.
let converted_time = abstractapi
.convert_time(
"Los Angeles,CA",
"2020-05-01 07:00:00",
"Oxford,United Kingdom",
)
.unwrap();
print_pretty("Base location time", converted_time.base_location);
print_pretty("Target location time", converted_time.target_location);
}