#[must_use]
pub fn timestamp() -> u64 {
env!("SOURCE_DATE_EPOCH").parse::<u64>().unwrap()
}
#[must_use]
pub fn profile() -> &'static str {
env!("EXPECT_PROFILE")
}
#[must_use]
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
#[must_use]
pub fn date_iso() -> &'static str {
env!("BUILD_DATE_ISO")
}
#[must_use]
pub fn datetime_iso() -> &'static str {
env!("BUILD_DATETIME_ISO")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_timestamp() {
let ts = timestamp();
assert!(ts > 1577836800, "Timestamp should be after 2020-01-01");
assert!(ts < 4102444800, "Timestamp should be before 2100-01-01");
}
#[test]
fn test_profile() {
let profile = profile();
assert!(
profile == "debug" || profile == "release",
"Profile should be either 'debug' or 'release', got: {profile}"
);
}
#[test]
fn test_version() {
let ver = version();
assert!(!ver.is_empty(), "Version should not be empty");
assert!(
ver.contains('.'),
"Version should contain at least one dot: {ver}"
);
}
#[test]
fn test_timestamp_consistency() {
let ts1 = timestamp();
let ts2 = timestamp();
assert_eq!(ts1, ts2, "Timestamp should be consistent across calls");
}
#[test]
fn test_profile_consistency() {
let p1 = profile();
let p2 = profile();
assert_eq!(p1, p2, "Profile should be consistent across calls");
}
#[test]
fn test_date_iso() {
let date = date_iso();
assert_eq!(date.len(), 10, "ISO date should be 10 characters");
assert!(date.contains('-'), "ISO date should contain dashes");
let year: u32 = date[0..4].parse().expect("Year should be numeric");
assert!((2020..=2100).contains(&year), "Year should be reasonable");
}
#[test]
fn test_datetime_iso() {
let datetime = datetime_iso();
assert!(
datetime.len() >= 19,
"ISO datetime should be at least 19 characters"
);
assert!(datetime.contains('T'), "ISO datetime should contain 'T'");
assert!(datetime.ends_with('Z'), "ISO datetime should end with 'Z'");
}
}