diff --git a/src/provider/data.rs b/src/provider/data.rs index aa24c185a..35a5fc49c 100644 --- a/src/provider/data.rs +++ b/src/provider/data.rs @@ -807,4 +807,6 @@ lazy_static::lazy_static! { ("narod.ru", &*P_YANDEX_RU), ("ziggo.nl", &*P_ZIGGO_NL), ].iter().copied().collect(); + + pub static ref PROVIDER_UPDATED: chrono::NaiveDate = chrono::NaiveDate::from_ymd(2020, 9, 19); } diff --git a/src/provider/mod.rs b/src/provider/mod.rs index c217813bb..bbc1e39cc 100644 --- a/src/provider/mod.rs +++ b/src/provider/mod.rs @@ -4,7 +4,8 @@ mod data; use crate::config::Config; use crate::dc_tools::EmailAddress; -use crate::provider::data::PROVIDER_DATA; +use crate::provider::data::{PROVIDER_DATA, PROVIDER_UPDATED}; +use chrono::{NaiveDateTime, NaiveTime}; #[derive(Debug, Display, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive)] #[repr(u8)] @@ -91,11 +92,18 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> { None } +// returns update timestamp in seconds, UTC, compatible for comparison with time() and database times +pub fn get_provider_update_timestamp() -> i64 { + NaiveDateTime::new(*PROVIDER_UPDATED, NaiveTime::from_hms(0, 0, 0)).timestamp_millis() / 1_000 +} + #[cfg(test)] mod tests { #![allow(clippy::indexing_slicing)] use super::*; + use crate::dc_tools::time; + use chrono::NaiveDate; #[test] fn test_get_provider_info_unexistant() { @@ -138,4 +146,16 @@ mod tests { let provider = get_provider_info("user@googlemail.com").unwrap(); assert!(provider.status == Status::PREPARATION); } + + #[test] + fn test_get_provider_update_timestamp() { + let timestamp_past = NaiveDateTime::new( + NaiveDate::from_ymd(2020, 9, 9), + NaiveTime::from_hms(0, 0, 0), + ) + .timestamp_millis() + / 1_000; + assert!(get_provider_update_timestamp() <= time()); + assert!(get_provider_update_timestamp() > timestamp_past); + } } diff --git a/src/provider/update.py b/src/provider/update.py index 5ad15f1b2..d9bdd8d26 100755 --- a/src/provider/update.py +++ b/src/provider/update.py @@ -4,6 +4,7 @@ import sys import os import yaml +import datetime out_all = "" out_domains = "" @@ -169,6 +170,12 @@ if __name__ == "__main__": out_all += " pub static ref PROVIDER_DATA: HashMap<&'static str, &'static Provider> = [\n" out_all += out_domains; - out_all += " ].iter().copied().collect();\n}" + out_all += " ].iter().copied().collect();\n\n" + + now = datetime.datetime.utcnow() + out_all += " pub static ref PROVIDER_UPDATED: chrono::NaiveDate = "\ + "chrono::NaiveDate::from_ymd("+str(now.year)+", "+str(now.month)+", "+str(now.day)+");\n" + + out_all += "}" print(out_all)