shift_algorithm/lib.rs
1//! # shift-algorithm
2//!
3//! **Core shift scheduling algorithm.** The foundation of the entire 班伴 (ShiftMate) project.
4//!
5//! Given any date, this crate determines what shift a worker is on,
6//! based on a repeating cycle shared across multiple teams.
7//!
8//! ## How it works
9//!
10//! The default cycle is 42 days, shared by 6 teams (一值~六值):
11//!
12//! ```text
13//! 早 早 中 中 休 夜 夜 休 休 早 早 中 中 休 夜 休 休 休 早 早 中 休
14//! 夜 夜 休 休 休 早 中 中 休 夜 夜 休 休 学 学 学 学 学 休 休
15//! ```
16//!
17//! Each team is offset by 7 days (42 / 6). Reference date 2025-12-15 is day 1.
18//! Team 1 starts at offset 0, team 2 at offset 7, etc.
19//!
20//! ## Quick start
21//!
22//! ```rust
23//! use shift_algorithm::cycle::default_config;
24//! use shift_algorithm::get_shift_info;
25//! use chrono::NaiveDate;
26//!
27//! let config = default_config();
28//! let today = NaiveDate::from_ymd_opt(2026, 5, 22).unwrap();
29//! let info = get_shift_info(today, &config, 0);
30//!
31//! println!("{:?} · day {}/{}",
32//! info.shift_type,
33//! info.day_of_cycle,
34//! config.cycle_length,
35//! );
36//! ```
37//!
38//! ## Crate structure
39//!
40//! - [`types`] — `ShiftType` enum, `ShiftInfo` struct, `ShiftCycleConfig`
41//! - [`cycle`] — Default constants (42-day cycle, reference date, 6 teams)
42//! - [`calculator`] — Pure functions: offset, normalize, get shift for date
43
44pub mod calculator;
45pub mod cycle;
46pub mod types;
47
48pub use calculator::*;
49pub use cycle::*;
50pub use types::*;