Skip to main content

Module date

Module date 

Source
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

FormatExample
Day full-month year5 กรกฎาคม 2567
Day abbreviated-month year5 ก.ค. 2567
With era marker5 ก.ค. พ.ศ. 2567
With วันที่ prefixวันที่ 5 กรกฎาคม 2567
Slash-separated5/7/2567
Dash-separated5-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§

ThaiDate
A parsed Thai date with day, month, year, and era.

Enums§

Era
Era system for a ThaiDate.

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.