| Crates.io | dostime |
| lib.rs | dostime |
| version | 2.0.0 |
| created_at | 2024-12-30 04:51:25.192985+00 |
| updated_at | 2025-06-16 14:49:34.987088+00 |
| description | A Rust crate that converts to and from MS DOS dates and times. |
| homepage | |
| repository | https://github.com/abus-sh/dostime |
| max_upload_size | |
| id | 1498774 |
| size | 104,944 |
This crate converts MS DOS times to and from various formats, including integers, byte arrays, and types in external crates (see the features for more information).
This crate is no_std compatible.
An explanation of the date and time formats can be found
here,
though the documentation for DOSTime and DOSDate also includes explantions for the format.
use dostime::{DOSDate, DOSTime, DOSDateTime};
use dostime::date::DateError;
use dostime::time::TimeError;
use dostime::datetime::DateTimeError;
// Valid dates and times can be constructed.
let date = DOSDate::new(2017, 4, 6).unwrap(); // 2017-04-06
let time = DOSTime::new(13, 24, 54).unwrap(); // 13:24:54
let datetime = DOSDateTime::new(2006, 4, 15, 1, 5, 34); // 2006-04-15 01:05:34
// Invalid dates and times can't be constructed and information about what is invalid is
// returned.
let invalid_month = DOSDate::new(1996, 13, 3).unwrap_err();
assert_eq!(invalid_month, DateError::InvalidMonth);
let invalid_second = DOSTime::new(1, 2, 60).unwrap_err();
assert_eq!(invalid_second, TimeError::InvalidSecond);
let invalid_day = DOSDateTime::new(2001, 4, 31, 6, 13, 12).unwrap_err();
assert_eq!(invalid_day, DateTimeError::DateError(DateError::InvalidDay));
// Dates and times can be converted to and from integers and arrays of bytes.
let int: u16 = date.into();
assert_eq!(int, 0x4A86);
assert_eq!(date, DOSDate::try_from(0x4A86).unwrap());
let bytes: [u8; 2] = time.into();
assert_eq!(bytes, [0x1B, 0x6B]);
assert_eq!(time, DOSTime::try_from([0x1B, 0x6B]).unwrap());
serde-1 - enables (de)serialization with Serdetime-1 - enables conversion to/from types in the time crate (Date, Time, and
PrimitiveDateTime)chrono-1 - enables conversion to/from types in the chrono crate (NaiveDate, NaiveTime, and
NaiveDateTime)If anyone thinks of something else that this crate should have or spots any bugs, let me know! I'll see if I can add it. Alternatively, feel free to submit a pull request (or just fork it). I'll review and approve it as soon as I can.