Expand description
Thai date normalization.
Parses Thai date strings (Buddhist Era or Gregorian) into a structured ThaiDate
and formats them back to ISO 8601 or Thai text.
§Supported input formats
| Format | Example |
|---|---|
| Day full-month year | 5 กรกฎาคม 2567 |
| Day abbreviated-month year | 5 ก.ค. 2567 |
| With era marker | 5 ก.ค. พ.ศ. 2567 |
| With วันที่ prefix | วันที่ 5 กรกฎาคม 2567 |
| Slash-separated | 5/7/2567 |
| Dash-separated | 5-7-2567 |
| Thai digits | ๕ ก.ค. ๒๕๖๗ |
§Era inference
When no era marker is present, the year is heuristically classified:
- year ≥ 2300 → Buddhist Era (พ.ศ.)
- year < 2300 → Gregorian (ค.ศ.)
§Examples
use kham_core::date::{parse_thai_date, Era};
let d = parse_thai_date("5 กรกฎาคม 2567").unwrap();
assert_eq!(d.day, 5);
assert_eq!(d.month, 7);
assert_eq!(d.year, 2567);
assert!(matches!(d.era, Era::Buddhist));
assert_eq!(d.to_iso8601(), "2024-07-05");
let d2 = parse_thai_date("5/7/2567").unwrap();
assert_eq!(d2.to_iso8601(), "2024-07-05");Structs§
- Thai
Date - A parsed Thai date with day, month, year, and era.
Enums§
Functions§
- format_
thai_ date - Formats a Buddhist Era date as Thai text:
"5 กรกฎาคม พ.ศ. 2567". - parse_
thai_ date - Parses a Thai date string into a
ThaiDate.