Adds a single helper function

This commit is contained in:
Dandaedre 2024-11-29 17:47:56 +01:00
parent 2ac6929ab1
commit 4609d910da
5 changed files with 17 additions and 7 deletions

View File

@ -11,6 +11,9 @@
//!
//! Please note that while an invalid input will return an error, a partially valid input will yield partial results.
//!
//! # Functions
//! The following functions are used to parse user data:
//! * [parse_simple_date]
//! ### Usage
//! ```
//! use idlefox::date::parse_str_into_date;
@ -249,7 +252,7 @@ fn parse_weekday(input: &str) -> IResult<&str, Weekday> {
/// The function uses the [nom::branch::alt] combinator to handle the different date formats.
/// Each format is represented by a separate [nom::combinator::map] combinator that extracts
/// the necessary date information and constructs the DatePoint object.
fn parse_simple_date(input: &str) -> IResult<&str, DatePoint> {
pub fn parse_simple_date(input: &str) -> IResult<&str, DatePoint> {
alt((
map(
tuple((space0, parse_month, space0, digit1, space0)),

View File

@ -1,6 +1,6 @@
//! Utilities to handle date and relative date selection
use crate::error_handling::IdleError;
use crate::{date::date_parse::parse_simple_date, error_handling::IdleError};
use chrono::{Datelike, Duration, Local, Month, Months, NaiveDate, Weekday};
use serde::{Deserialize, Serialize};
@ -316,6 +316,11 @@ pub fn parse_date_list(
NaiveDateList::from_context(objects, context, leftover)
}
pub fn parse_single_date(input: &str, context: Option<NaiveDate>) -> Result<NaiveDate, IdleError> {
// As we simply ignore the leftover, we can directly call the to_naive_date method
parse_simple_date(input)?.1.to_naive_date(context)
}
#[cfg(test)]
pub(crate) mod tests {
use super::*;

View File

@ -17,6 +17,7 @@
//! left after processing the input, they can be retrieved using the `unparsed` method on the returned `Result`.
//!
//! The function uses the context provided to resolve any relative dates within the input string.
//! - [parse_single_date]
//!
//! # Examples
//!
@ -54,6 +55,7 @@ pub mod date_tools;
// Republishing important functions
pub use date_parse::parse_str_into_date;
pub use date_tools::parse_date_list;
pub use date_tools::parse_single_date;
pub use date_tools::NaiveDateList;
pub use date_tools::NaiveDateObject;

View File

@ -145,8 +145,8 @@ impl Default for WeeklyVoteModal {
title: "The base test vote".into(),
description: "Dummy vote".into(),
group: Some("Base group".into()),
hours: Some("21h - 23".into()),
short_name: Some("Base vote".into()),
start_date: todo!(),
non_days: todo!(),
}
}
}
@ -168,8 +168,8 @@ pub async fn vote_modal(
underlying_data.group,
underlying_data.title,
underlying_data.description,
underlying_data.short_name,
underlying_data.hours
underlying_data.title,
underlying_data.non_days
);
// This whole shenennigan only exists to find a group as specified by text and if so apply it

View File

@ -22,7 +22,7 @@ pub fn handler(vote_container: VoteContainer) {
// TODO: Give vky the tools to parse dates and time
// Needs to be parsed as start and end hours
let short_name = vote_container.short_name;
// let short_name = vote_container.short_name;
// Needs to be parsed as single date or set to today's date if None
let mut non_days = vote_container.non_days;
// Needs to be parsed as a list of days spanning one week after start_date