xsd_types/value/
g_month.rs

1use chrono::FixedOffset;
2
3use crate::{format_timezone, Datatype, ParseXsd, XsdValue};
4use core::fmt;
5
6#[derive(Debug, Clone, Copy)]
7pub struct GMonth {
8	month: u8,
9	offset: Option<FixedOffset>,
10}
11
12impl GMonth {
13	pub fn new(month: u8, offset: Option<FixedOffset>) -> Option<Self> {
14		if (1..=12).contains(&month) {
15			Some(Self { month, offset })
16		} else {
17			None
18		}
19	}
20}
21
22impl XsdValue for GMonth {
23	fn datatype(&self) -> Datatype {
24		Datatype::GMonth
25	}
26}
27
28impl ParseXsd for GMonth {
29	type LexicalForm = crate::lexical::GMonth;
30}
31
32impl fmt::Display for GMonth {
33	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34		write!(f, "--{:02}", self.month)?;
35
36		format_timezone(self.offset, f)
37	}
38}