Skip to content

Is there a reason that DateTime::num_days_in_month() returns a u8 instead of a u32? #1759

Description

@ablesea

This does seem to be more correct since the value can only be 1-31 but this decision forces me to do unnecessary type casting fairly often in my code since it's the only (non length) function in the project that returns a u8 see: https://grep.app/search?f.repo=chronotope/chrono&f.repo.pattern=chrono&q=-%3E+u8

For example:

let expected_day = match monthly_the_frequency.the  {
    schedule::MonthlyTheOperator::First => 1,
    schedule::MonthlyTheOperator::Second => 2,
    schedule::MonthlyTheOperator::Third => 3,
    schedule::MonthlyTheOperator::Fourth => 4,
    schedule::MonthlyTheOperator::Last => current_time.num_days_in_month(),
};
// this won't compile because current_time.day() returns a u32
if current_time.day() != expected_day {
    return Ok(vec![]);
}

Happy to make a PR if you think this is valid!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions