feat: sort dates list before displaying the list

This commit is contained in:
alphafetus committed 2026-01-15 13:57:59 -05:00
1 parent f15d151694
commit 7d7c96e642
4 files changed
+150 -99

No files matched your search

+48 -12
View File
@@ -1,14 +1,20 @@
use chrono::{DateTime, FixedOffset};
use chrono::{DateTime, FixedOffset, Local};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DateInfo {
#[serde()]
pub(crate) title: String,
#[serde(rename = "date")]
pub(crate) date: DateRange,
#[serde(rename = "desc")]
pub(crate) description: String,
pub id: String,
pub title: String,
pub date: DateRange,
pub description: String,
}
impl DateInfo {
pub fn get_start_date(&self) -> DateTime<FixedOffset> {
match self.date {
DateRange::Single(date) | DateRange::Range(date, _) => date,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -17,11 +23,41 @@ pub enum DateRange {
Range(DateTime<FixedOffset>, DateTime<FixedOffset>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
impl DateRange {
pub fn get_status(&self) -> DateStatus {
match self {
DateRange::Single(_) => DateStatus::Blank,
DateRange::Range(start_date, end_date) => {
let local = Local::now();
// Check the amount of time from now to the start date. Values that are negative
// indicate that the start date has already passed.
if dbg!(start_date.signed_duration_since(local).num_days()) > 0 {
DateStatus::Upcoming
} else {
// Check the amount of time from now to the end date. The value will be positive if
// the end date is in the future. We will be specific to the minute.
let duration_until = dbg!(end_date).signed_duration_since(local);
let num_days = dbg!(duration_until.num_days());
let num_mins = dbg!(duration_until.num_minutes());
if num_mins <= 0 {
DateStatus::Closed
} else if num_days <= 5 {
DateStatus::Deadline
} else {
DateStatus::Open
}
}
}
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Ord)]
pub enum DateStatus {
Closed,
Deadline,
Open,
Upcoming,
Blank,
Upcoming,
Open,
Deadline,
Closed,
}