Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_datime/src/core/validation.rs

1.0 KiB, 14 runs

created by r1870400018:6361, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\
2//! Anthropic Claude
3
4use oxedyne_fe2o3_core::prelude::*;
5
6pub struct TimeValidation;
7
8impl TimeValidation {
9 pub fn is_valid_year(year: i32) -> bool {
10 year >= -9999 && year <= 9999
11 }
12
13 pub fn is_valid_month(month: u8) -> bool {
14 month >= 1 && month <= 12
15 }
16
17 pub fn is_valid_day(year: i32, month: u8, day: u8) -> Outcome<bool> {
18 use crate::constant::MonthOfYear;
19
20 if day == 0 {
21 return Ok(false);
22 }
23
24 let month_enum = res!(MonthOfYear::from_number(month));
25 let days_in_month = month_enum.days_in_month(year);
26
27 Ok(day <= days_in_month)
28 }
29
30 pub fn is_valid_hour(hour: u8) -> bool {
31 hour <= 23
32 }
33
34 pub fn is_valid_minute(minute: u8) -> bool {
35 minute <= 59
36 }
37
38 pub fn is_valid_second(second: u8) -> bool {
39 second <= 59
40 }
41
42 pub fn is_valid_nanosecond(nano: u32) -> bool {
43 nano <= 999_999_999
44 }
45}