Skip to main content

rpc/forms/
report_clock.rs

1//! The user's zone, which report dates are read in.
2
3use server::command::CmdResult;
4use server::command::config::GetTimezone;
5use server::timezone::Tz;
6use uuid::Uuid;
7
8use super::Failure;
9
10const CTX: &str = "report";
11
12/// The zone of `user_id`'s reports; UTC when they set none.
13///
14/// # Errors
15/// A refusal when the stored value is not a zone, an internal failure otherwise.
16pub async fn user_zone(user_id: Uuid) -> Result<Tz, Failure> {
17    match GetTimezone::new()
18        .user_id(user_id)
19        .run()
20        .await
21        .map_err(|err| Failure::from_command(CTX, err))?
22    {
23        Some(CmdResult::Timezone(zone)) => Ok(zone),
24        _ => Err(Failure::Internal(wasmtime::Error::msg(
25            "get-timezone: unexpected result",
26        ))),
27    }
28}