Implement catchup hours logic

This commit is contained in:
2024-09-19 21:26:57 +02:00
parent 09c25a67c5
commit fe0bc03c03
6 changed files with 62 additions and 6 deletions

View File

@ -1,3 +1,4 @@
use chrono::prelude::*;
use std::time::{SystemTime, UNIX_EPOCH};
/// Get the current time since epoch
@ -16,11 +17,25 @@ pub fn time_millis() -> u128 {
.as_millis()
}
/// Get the number of the day since 01-01-1970 of a given UNIX timestamp
/// Get the number of the day since 01-01-1970 of a given UNIX timestamp (UTC)
pub fn day_number(time: u64) -> u64 {
time / (3600 * 24)
}
/// Get current hour, 00 => 23 (local time)
pub fn curr_hour() -> u32 {
let local: DateTime<Local> = Local::now();
local.hour()
}
/// Get the first second of the day (local time)
pub fn time_start_of_day() -> anyhow::Result<u64> {
let local: DateTime<Local> = Local::now()
.with_time(NaiveTime::from_hms_opt(0, 0, 0).unwrap())
.unwrap();
Ok(local.timestamp() as u64)
}
#[cfg(test)]
mod test {
use crate::utils::time_utils::day_number;