Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change the behavior of DateTime::from_msdos when value is invalid #145

@sorairolake

Description

@sorairolake

Is your feature request related to a problem? Please describe.
DateTime::from_msdos can create a DateTime value even if datepart or timepart is an invalid value.

zip2/src/types.rs

Lines 139 to 156 in 6c60c67

/// Converts an msdos (u16, u16) pair to a DateTime object
pub const fn from_msdos(datepart: u16, timepart: u16) -> DateTime {
let seconds = (timepart & 0b0000000000011111) << 1;
let minutes = (timepart & 0b0000011111100000) >> 5;
let hours = (timepart & 0b1111100000000000) >> 11;
let days = datepart & 0b0000000000011111;
let months = (datepart & 0b0000000111100000) >> 5;
let years = (datepart & 0b1111111000000000) >> 9;
DateTime {
year: years + 1980,
month: months as u8,
day: days as u8,
hour: hours as u8,
minute: minutes as u8,
second: seconds as u8,
}
}

Describe the solution you'd like
I would like one of the following:

A clear and concise description of what you want to happen.

  1. Make DateTime::from_msdos an unsafe function.
  2. Returns Err if datepart or timepart is invalid.
  3. Panics if datepart or timepart is invalid.

Describe alternatives you've considered
Specify in the documentation that an invalid DateTime value may be created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfix mergedFix is merged, but the issue will stay open until it's released.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions