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
39
40
41
42
43
44
//---------------------------------------------------------------------------------------------------- Ok
#[inline(always)]
/// If `year` is in-between `1000..=9999`
pub(crate) const fn ok_year(year: u16) -> bool {
	year >= 1000 && year <= 9999
}

#[inline(always)]
/// If `month` is in-between `1..=12`
pub(crate) const fn ok_month(month: u8) -> bool {
	month >= 1 && month <= 12
}

#[inline(always)]
/// If `day` is in-between `1..=31`
pub(crate) const fn ok_day(day: u8) -> bool {
	day >= 1 && day <= 31
}

#[inline(always)]
/// If `ok_year`, `ok_month`, and `ok_day` are all okay
pub(crate) const fn ok(year: u16, month: u8, day: u8) -> bool {
	ok_year(year) && ok_month(month) && ok_day(day)
}

//---------------------------------------------------------------------------------------------------- Date
#[inline]
/// Get the current system date in the system's timezone.
///
/// The returned value is `(year, month, day)`.
pub fn date() -> (i16, u8, u8) {
	use chrono::Datelike;
	let now = chrono::offset::Local::now().date_naive();
	(now.year() as i16, now.month() as u8, now.day() as u8)
}

#[inline]
/// Get the current system date in UTC locale
///
/// The returned value is `(year, month, day)`.
pub fn date_utc() -> (i16, u8, u8) {
	let unix = chrono::offset::Local::now().timestamp() as i128;
	nichi::Date::from_unix(unix).inner()
}