standard_version/calver/mod.rs
1//! Calendar versioning (calver) support.
2//!
3//! Computes the next calver version from a format string, the current date,
4//! and the previous version string. The format string uses tokens like
5//! `YYYY`, `MM`, `PATCH`, etc.
6//!
7//! This module is pure — it takes the date as a parameter and performs no I/O.
8
9pub mod bump;
10pub mod parse;
11
12pub use bump::{next_version, validate_format};
13
14/// Date information needed for calver computation.
15///
16/// All fields are simple integers — the caller is responsible for computing
17/// them from the current date. This keeps the library pure (no clock access).
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct CalverDate {
20 /// Full year (e.g. 2026).
21 pub year: u32,
22 /// Month (1–12).
23 pub month: u32,
24 /// Day of month (1–31).
25 pub day: u32,
26 /// ISO week number (1–53).
27 pub iso_week: u32,
28 /// ISO day of week (1=Monday, 7=Sunday).
29 pub day_of_week: u32,
30}
31
32/// The default calver format when none is specified.
33pub const DEFAULT_FORMAT: &str = "YYYY.MM.PATCH";
34
35/// Errors that can occur during calver computation.
36#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
37pub enum CalverError {
38 /// The format string contains no `PATCH` token.
39 #[error("calver format must contain the PATCH token")]
40 NoPatchToken,
41 /// The format string contains an unrecognised token.
42 #[error("unknown calver format token: {0}")]
43 UnknownToken(String),
44 /// The format string is empty.
45 #[error("calver format string is empty")]
46 EmptyFormat,
47}