legit-hamming 0.1.1

Exact Hamming radius search over 64-bit and 256-bit hashes in memory: a scan or multi-index hashing, chosen per query, checked against one reference, and a search service over snapshots
Documentation
//! Times as RFC 3339 text, without a date library.

use std::time::{SystemTime, UNIX_EPOCH};

/// `time` in UTC as RFC 3339 to the millisecond, such as `2026-12-02T12:00:00.000Z`. A time
/// before 1970 is written as the epoch.
///
/// ```
/// use std::time::{Duration, UNIX_EPOCH};
///
/// let time = UNIX_EPOCH + Duration::from_millis(1_764_676_800_250);
/// assert_eq!(legit_hamming::service::rfc3339(time), "2025-12-02T12:00:00.250Z");
/// ```
#[must_use]
pub fn rfc3339(time: SystemTime) -> String {
    let since = time.duration_since(UNIX_EPOCH).unwrap_or_default();
    let seconds = since.as_secs();
    let (days, rest) = (seconds / 86_400, seconds % 86_400);
    let (year, month, day) = civil(days);
    format!(
        "{year:04}-{month:02}-{day:02}T{:02}:{:02}:{:02}.{:03}Z",
        rest / 3600,
        rest % 3600 / 60,
        rest % 60,
        since.subsec_millis()
    )
}

/// The year, month and day of a count of days since 1970-01-01, by Howard Hinnant's
/// `civil_from_days`.
const fn civil(days: u64) -> (u64, u64, u64) {
    let z = days + 719_468;
    let era = z / 146_097;
    let day_of_era = z - era * 146_097;
    let year_of_era = (day_of_era - day_of_era / 1460 + day_of_era / 36_524 - day_of_era / 146_096) / 365;
    let day_of_year = day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
    let shifted_month = (5 * day_of_year + 2) / 153;
    let day = day_of_year - (153 * shifted_month + 2) / 5 + 1;
    let month = if shifted_month < 10 {
        shifted_month + 3
    } else {
        shifted_month - 9
    };
    let year = year_of_era + era * 400 + if month <= 2 { 1 } else { 0 };
    (year, month, day)
}