summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/date.rs51
-rw-r--r--src/lib.rs2
2 files changed, 53 insertions, 0 deletions
diff --git a/src/date.rs b/src/date.rs
new file mode 100644
index 0000000..6cd5f48
--- /dev/null
+++ b/src/date.rs
@@ -0,0 +1,51 @@
+use crate::{Month, Year};
+
+#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+pub struct Date {
+ year: Year,
+ month: Month,
+ day: u8,
+}
+
+impl Date {
+ /// The earliest date which can be represented
+ pub const MIN: Self =
+ unsafe { Self::from_calendar_date_unchecked(Year::MIN, Month::January, 1) };
+
+ /// The latest date which can be represented
+ pub const MAX: Self =
+ unsafe { Self::from_calendar_date_unchecked(Year::MAX, Month::December, 31) };
+
+ // TODO validated from_calendar_date
+
+ /// Creates a date without checking to make sure that it's valid.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use botic::Date;
+ ///
+ /// let y2k = unsafe {
+ /// Date::from_calendar_date_unchecked(Year::from(2000), Month::January, 1)
+ /// };
+ /// ```
+ ///
+ /// # Safety
+ ///
+ /// This function results in undefined behavior if the given date is not a real date
+ pub const unsafe fn from_calendar_date_unchecked(year: Year, month: Month, day: u8) -> Self {
+ Self { year, month, day }
+ }
+
+ pub const fn year(self) -> Year {
+ self.year
+ }
+
+ pub const fn month(self) -> Month {
+ self.month
+ }
+
+ pub const fn day(self) -> u8 {
+ self.day
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index fdfeb5c..4fbfaf9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,11 @@
#![doc = include_str!("../README.md")]
+mod date;
mod month;
mod weekday;
mod year;
+pub use date::Date;
pub use month::Month;
pub use weekday::Weekday;
pub use year::Year;