Function regorust::set_tzdata_path
source · pub fn set_tzdata_path(path: &str, download: bool) -> Result<(), &'static str>
Expand description
Sets the path to the TZData directory.
Some of the time
built-ins require access to the IANA tzdata database
in order to resolve timezone names. If the TZ data path is not set, these
built-ins will not function properly. This function allows you to point the
Rego interpreter to the location of the TZ data. Optionally, you can request
that the latest TZ data be downloaded to the path you specify.
§Example
use regorust::*;
let path = "./tzdata";
set_tzdata_path(path, true).expect("cannot set TZData path");
let rego = Interpreter::new();
match rego.query(r#"x=time.clock([1727267567139080131, "America/Los_Angeles"])"#) {
Ok(result) => {
let x = result.binding("x").expect("cannot get x");
println!("x = {}", x.json().unwrap());
if let NodeValue::Int(hour) = x
.index(0)
.unwrap()
.value()
.unwrap()
{
println!("hour = {}", hour);
}
if let NodeValue::Int(minute) = x
.index(1)
.unwrap()
.value()
.unwrap()
{
println!("minute = {}", minute);
}
if let NodeValue::Int(second) = x
.index(2)
.unwrap()
.value()
.unwrap()
{
println!("second = {}", second);
}
}
Err(e) => {
panic!("error: {}", e);
}
}