Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strptime() not handling optionality of leading zeroes #25

Closed
mikedilger opened this issue Dec 1, 2014 · 0 comments · Fixed by #88
Closed

strptime() not handling optionality of leading zeroes #25

mikedilger opened this issue Dec 1, 2014 · 0 comments · Fixed by #88

Comments

@mikedilger
Copy link

For many format specifiers, leading zeroes are supposed to be optional: http://pubs.opengroup.org/onlinepubs/7908799/xsh/strptime.html

I have only tested %m.

[package]
name = "test"
version = "0.0.0"
authors = [ "mike@mikedilger.com" ]

[[bin]]
name = "test"
path = "main.rs"

[dependencies]
time = "*"
extern crate time;

use time::strptime;

fn main() {
    // %m is the month number [1,12]; leading zeros are permitted but not required.
    let format = "%d/%m/%Y".into_string();
    let dates = [ "24/05/2016", "24/5/2016" ];

    for date in dates.iter() {
        match strptime(*date, format.as_slice() ) {
            Ok(d) => println!("{} is valid {}, result shows as {}", date, format, d),
            Err(e) => println!("{} is invalid {} -- {}", date, format, e),
        }
    }
}
24/05/2016 is valid %d/%m/%Y, result shows as Tm { tm_sec: 0, tm_min: 0, tm_hour: 0, tm_mday: 24, tm_mon: 4, tm_year: 116, tm_wday: 0, tm_yday: 0, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 0 }
24/5/2016 is invalid %d/%m/%Y -- Invalid month.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants