Skip to content

extra: %W and %+ support in time::strftime #9689

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

Merged
merged 1 commit into from
Oct 3, 2013
Merged
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
15 changes: 7 additions & 8 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
}

fn parse_type(ch: char, tm: &Tm) -> ~str {
//FIXME (#2350): Implement missing types.
let die = || format!("strftime: can't understand this format {} ", ch);
match ch {
'A' => match tm.tm_wday as int {
Expand Down Expand Up @@ -920,10 +919,9 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
parse_type('b', tm),
parse_type('Y', tm))
}
//'W' {}
'W' => format!("{:02d}", (tm.tm_yday - (tm.tm_wday - 1 + 7) % 7 + 7)
/ 7),
'w' => (tm.tm_wday as int).to_str(),
//'X' {}
//'x' {}
'Y' => (tm.tm_year as int + 1900).to_str(),
'y' => format!("{:02d}", (tm.tm_year as int + 1900) % 100),
'Z' => tm.tm_zone.clone(),
Expand All @@ -934,7 +932,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
m -= h * 60_i32;
format!("{}{:02d}{:02d}", sign, h, m)
}
//'+' {}
'+' => tm.rfc3339(),
'%' => ~"%",
_ => die()
}
Expand Down Expand Up @@ -1297,12 +1295,13 @@ mod tests {
assert_eq!(local.strftime("%u"), ~"5");
assert_eq!(local.strftime("%V"), ~"07");
assert_eq!(local.strftime("%v"), ~"13-Feb-2009");
// assert!(local.strftime("%W") == "06");
assert_eq!(local.strftime("%W"), ~"06");
assert_eq!(local.strftime("%w"), ~"5");
// handle "%X"
// handle "%x"
assert_eq!(local.strftime("%X"), ~"15:31:30"); // FIXME (#2350): support locale
assert_eq!(local.strftime("%x"), ~"02/13/09"); // FIXME (#2350): support locale
assert_eq!(local.strftime("%Y"), ~"2009");
assert_eq!(local.strftime("%y"), ~"09");
assert_eq!(local.strftime("%+"), ~"2009-02-13T15:31:30-08:00");

// FIXME (#2350): We should probably standardize on the timezone
// abbreviation.
Expand Down