Skip to content

fixes for time:strptime #9707

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,25 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
.and_then(|pos| parse_char(s, pos, '-'))
.and_then(|pos| parse_type(s, pos, 'Y', &mut *tm))
}
//'W' {}
'W' => {
match match_digits_in_range(s, pos, 2u, false, 0_i32, 52_i32) {
Some(item) => {
let (v, pos) = item; // If the day of the week has been set,
if tm.tm_wday != 7i32 { // get day of the year with it.
tm.tm_yday = ((7 - tm.tm_wday) % 7 + (v - 1) * 7
+ (tm.tm_wday + 7) % 7);
}
Ok(pos)
}
None => Err(~"Invalid week number")
}
}
'w' => {
match match_digits_in_range(s, pos, 1u, false, 0_i32, 6_i32) {
Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) }
None => Err(~"Invalid day of week")
}
}
//'X' {}
//'x' {}
'Y' => {
match match_digits(s, pos, 4u, false) {
Some(item) => {
Expand Down Expand Up @@ -676,7 +686,7 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
tm_mday: 0_i32,
tm_mon: 0_i32,
tm_year: 0_i32,
tm_wday: 0_i32,
tm_wday: 7_i32,
tm_yday: 0_i32,
tm_isdst: 0_i32,
tm_gmtoff: 0_i32,
Expand Down Expand Up @@ -706,6 +716,9 @@ pub fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
}
}

// Day of the week wasn't set, so resetting to zero.
if tm.tm_wday == 7i32 { tm.tm_wday = 0i32; }

if pos == len && rdr.eof() {
Ok(Tm {
tm_sec: tm.tm_sec,
Expand Down