Skip to content

Commit 2076073

Browse files
committed
auto merge of #9689 : luisbg/rust/strftime, r=alexcrichton
Plus testing added for %X and %x which were supported but not tested. Working towards #2350
2 parents 371a7ec + 8f6e43e commit 2076073

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/libextra/time.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
788788
}
789789

790790
fn parse_type(ch: char, tm: &Tm) -> ~str {
791-
//FIXME (#2350): Implement missing types.
792791
let die = || format!("strftime: can't understand this format {} ", ch);
793792
match ch {
794793
'A' => match tm.tm_wday as int {
@@ -920,10 +919,9 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
920919
parse_type('b', tm),
921920
parse_type('Y', tm))
922921
}
923-
//'W' {}
922+
'W' => format!("{:02d}", (tm.tm_yday - (tm.tm_wday - 1 + 7) % 7 + 7)
923+
/ 7),
924924
'w' => (tm.tm_wday as int).to_str(),
925-
//'X' {}
926-
//'x' {}
927925
'Y' => (tm.tm_year as int + 1900).to_str(),
928926
'y' => format!("{:02d}", (tm.tm_year as int + 1900) % 100),
929927
'Z' => tm.tm_zone.clone(),
@@ -934,7 +932,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
934932
m -= h * 60_i32;
935933
format!("{}{:02d}{:02d}", sign, h, m)
936934
}
937-
//'+' {}
935+
'+' => tm.rfc3339(),
938936
'%' => ~"%",
939937
_ => die()
940938
}
@@ -1297,12 +1295,13 @@ mod tests {
12971295
assert_eq!(local.strftime("%u"), ~"5");
12981296
assert_eq!(local.strftime("%V"), ~"07");
12991297
assert_eq!(local.strftime("%v"), ~"13-Feb-2009");
1300-
// assert!(local.strftime("%W") == "06");
1298+
assert_eq!(local.strftime("%W"), ~"06");
13011299
assert_eq!(local.strftime("%w"), ~"5");
1302-
// handle "%X"
1303-
// handle "%x"
1300+
assert_eq!(local.strftime("%X"), ~"15:31:30"); // FIXME (#2350): support locale
1301+
assert_eq!(local.strftime("%x"), ~"02/13/09"); // FIXME (#2350): support locale
13041302
assert_eq!(local.strftime("%Y"), ~"2009");
13051303
assert_eq!(local.strftime("%y"), ~"09");
1304+
assert_eq!(local.strftime("%+"), ~"2009-02-13T15:31:30-08:00");
13061305
13071306
// FIXME (#2350): We should probably standardize on the timezone
13081307
// abbreviation.

0 commit comments

Comments
 (0)