oxedyne/fe2o3/fe2o3_datime/src/core/time.rs
1.4 KiB, 16 runs
created by r1870400018:6359, 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 | |
| 4 | use crate::time::CalClockZone; |
| 5 | |
| 6 | use oxedyne_fe2o3_core::prelude::*; |
| 7 | |
| 8 | use std::fmt::Debug; |
| 9 | |
| 10 | pub trait Time: Debug + Clone + PartialEq { |
| 11 | fn get_zone(&self) -> &CalClockZone; |
| 12 | |
| 13 | fn to_zone(&self, new_zone: CalClockZone) -> Outcome<Self>; |
| 14 | |
| 15 | fn format(&self, stencil: &str) -> String; |
| 16 | |
| 17 | fn is_recognised_format_char(&self, c: char) -> bool; |
| 18 | |
| 19 | fn is_before(&self, other: &Self) -> bool; |
| 20 | |
| 21 | fn is_after(&self, other: &Self) -> bool; |
| 22 | |
| 23 | fn or_earlier(&self, other: &Self) -> Self; |
| 24 | |
| 25 | fn or_later(&self, other: &Self) -> Self; |
| 26 | } |
| 27 | |
| 28 | /// The fundamental moments are a CalClock, a ClockTime naming a time of day, |
| 29 | /// and a CalendarDate naming a day of the year. |
| 30 | #[derive(Clone, Debug, PartialEq)] |
| 31 | pub struct AbstractTime { |
| 32 | zone: CalClockZone, |
| 33 | } |
| 34 | |
| 35 | impl AbstractTime { |
| 36 | pub fn new(zone: CalClockZone) -> Self { |
| 37 | Self { zone } |
| 38 | } |
| 39 | |
| 40 | pub fn new_default() -> Self { |
| 41 | Self { |
| 42 | zone: CalClockZone::default(), |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | pub fn compare_time<T: Time>(&self, this: &T, other: &T) -> Outcome<std::cmp::Ordering> { |
| 47 | if this.is_before(other) { |
| 48 | Ok(std::cmp::Ordering::Less) |
| 49 | } else if this == other { |
| 50 | Ok(std::cmp::Ordering::Equal) |
| 51 | } else { |
| 52 | Ok(std::cmp::Ordering::Greater) |
| 53 | } |
| 54 | } |
| 55 | } |