Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_datime/src/calendar/interval.rs

1.5 KiB, 7 runs

created by r1870400018:6299, 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 crate::{
5 calendar::{
6 CalendarDate,
7 CalendarDuration,
8 },
9 core::{Interval, Time},
10};
11
12use oxedyne_fe2o3_core::prelude::*;
13
14use std::fmt::{self, Display};
15
16#[derive(Clone, Debug, Eq, PartialEq)]
17pub struct CalendarInterval {
18 start: CalendarDate,
19 end: CalendarDate,
20}
21
22impl CalendarInterval {
23 pub fn new(start: CalendarDate, end: CalendarDate) -> Outcome<Self> {
24 if end.is_before(&start) {
25 return Err(err!(
26 "End date {} is before start date {}",
27 end, start;
28 Invalid, Input, Order));
29 }
30
31 Ok(Self { start, end })
32 }
33
34 pub fn start(&self) -> &CalendarDate {
35 &self.start
36 }
37
38 pub fn end(&self) -> &CalendarDate {
39 &self.end
40 }
41
42 pub fn duration(&self) -> Outcome<CalendarDuration> {
43 self.end.minus_date(&self.start)
44 }
45}
46
47impl Interval<CalendarDuration> for CalendarInterval {
48 fn get_duration(&self) -> Outcome<CalendarDuration> {
49 self.duration()
50 }
51
52 fn contains<T: Time>(&self, _time: &T) -> bool {
53 // Placeholder - would need type-specific logic
54 false
55 }
56
57 fn overlaps(&self, _other: &Self) -> bool {
58 // Placeholder - would need proper date comparison logic
59 false
60 }
61}
62
63impl Display for CalendarInterval {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 write!(f, "{} to {}", self.start, self.end)
66 }
67}