use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AgeStatus {
Active,
Stale,
Frozen,
}
impl AgeStatus {
pub fn label(self) -> &'static str {
match self {
AgeStatus::Active => "ACTIVE",
AgeStatus::Stale => "STALE",
AgeStatus::Frozen => "FROZEN",
}
}
}
pub struct FileAge {
pub path: PathBuf,
pub language: String,
pub last_modified: i64,
pub age_days: u64,
pub status: AgeStatus,
}
pub struct AgeThresholds {
pub active_days: u64,
pub frozen_days: u64,
}
impl Default for AgeThresholds {
fn default() -> Self {
Self {
active_days: 90,
frozen_days: 365,
}
}
}
pub fn classify(
path: PathBuf,
language: &str,
last_modified: i64,
now: i64,
thresholds: &AgeThresholds,
) -> FileAge {
let age_days = ((now - last_modified).max(0) as u64) / 86_400;
let status = if age_days < thresholds.active_days {
AgeStatus::Active
} else if age_days < thresholds.frozen_days {
AgeStatus::Stale
} else {
AgeStatus::Frozen
};
FileAge {
path,
language: language.to_string(),
last_modified,
age_days,
status,
}
}
#[cfg(test)]
#[path = "analyzer_test.rs"]
mod tests;