1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use chrono::FixedOffset;

use crate::{format_timezone, Datatype, ParseXsd, XsdValue};
use core::fmt;

#[derive(Debug, Clone, Copy)]
pub struct GMonth {
	month: u8,
	offset: Option<FixedOffset>,
}

impl GMonth {
	pub fn new(month: u8, offset: Option<FixedOffset>) -> Option<Self> {
		if (1..=12).contains(&month) {
			Some(Self { month, offset })
		} else {
			None
		}
	}
}

impl XsdValue for GMonth {
	fn datatype(&self) -> Datatype {
		Datatype::GMonth
	}
}

impl ParseXsd for GMonth {
	type LexicalForm = crate::lexical::GMonth;
}

impl fmt::Display for GMonth {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		write!(f, "--{:02}", self.month)?;

		format_timezone(self.offset, f)
	}
}