Print opening times in local time
This commit is contained in:
parent
27214dbc34
commit
4d06a1df84
3 changed files with 39 additions and 3 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -1516,6 +1516,15 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.29.0"
|
||||
|
@ -2391,8 +2400,12 @@ version = "0.3.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"libc",
|
||||
"num_threads",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2401,6 +2414,15 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
|
||||
dependencies = [
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
|
|
|
@ -18,7 +18,7 @@ reqwest = { version = "0.11.12", features = ["json"] }
|
|||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
spaceapi = "0.8.1"
|
||||
thiserror = "1.0.37"
|
||||
time = "0.3.17"
|
||||
time = { version = "0.3.17", features = ["local-offset", "formatting", "macros"] }
|
||||
tokio = { version = "1.21.2", features = ["full"] }
|
||||
toml = "0.5.9"
|
||||
url = { version = "2.3.1", features = ["serde"] }
|
||||
|
|
16
src/bot.rs
16
src/bot.rs
|
@ -25,7 +25,7 @@ use matrix_sdk::{
|
|||
use never_say_never::Never;
|
||||
use reqwest::Url;
|
||||
use serde::Deserialize;
|
||||
use time::OffsetDateTime;
|
||||
use time::{ext::NumericalDuration, macros::format_description, OffsetDateTime, UtcOffset};
|
||||
use tokio::time::sleep;
|
||||
use tracing::{event, instrument, span, Level};
|
||||
|
||||
|
@ -228,8 +228,22 @@ impl Bot {
|
|||
"isitopen" => {
|
||||
match self.update_open_state().await? {
|
||||
OpenState::Open { since } => {
|
||||
if let Ok(offset) = UtcOffset::current_local_offset() {
|
||||
let since = since.to_offset(offset);
|
||||
|
||||
let s = if OffsetDateTime::now_utc() - since > 20.hours() {
|
||||
since.format(format_description!(
|
||||
"[year]-[month]-[day] [hour]:[minute]:[second]"
|
||||
))?
|
||||
} else {
|
||||
since.format(format_description!("[hour]:[minute]:[second]"))?
|
||||
};
|
||||
|
||||
reply(&format!("positive! space has been open since {s}")).await?
|
||||
} else {
|
||||
reply(&format!("positive! space has been open since {since}")).await?
|
||||
}
|
||||
}
|
||||
OpenState::Closed => reply("negative!").await?,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue