|
@@ -1,9 +1,15 @@
|
|
use alloc::string::String;
|
|
use alloc::string::String;
|
|
-use platform::Write;
|
|
|
|
use platform::types::*;
|
|
use platform::types::*;
|
|
|
|
+use platform::Write;
|
|
use tm;
|
|
use tm;
|
|
|
|
|
|
-pub unsafe fn strftime<W: Write>(toplevel: bool, mut w: &mut W, maxsize: usize, mut format: *const c_char, t: *const tm) -> size_t {
|
|
|
|
|
|
+pub unsafe fn strftime<W: Write>(
|
|
|
|
+ toplevel: bool,
|
|
|
|
+ mut w: &mut W,
|
|
|
|
+ maxsize: usize,
|
|
|
|
+ mut format: *const c_char,
|
|
|
|
+ t: *const tm,
|
|
|
|
+) -> size_t {
|
|
let mut written = 0;
|
|
let mut written = 0;
|
|
if toplevel {
|
|
if toplevel {
|
|
// Reserve nul byte
|
|
// Reserve nul byte
|
|
@@ -52,7 +58,7 @@ pub unsafe fn strftime<W: Write>(toplevel: bool, mut w: &mut W, maxsize: usize,
|
|
"Wednesday",
|
|
"Wednesday",
|
|
"Thursday",
|
|
"Thursday",
|
|
"Friday",
|
|
"Friday",
|
|
- "Saturday"
|
|
|
|
|
|
+ "Saturday",
|
|
];
|
|
];
|
|
const MONTHS: [&'static str; 12] = [
|
|
const MONTHS: [&'static str; 12] = [
|
|
"January",
|
|
"January",
|
|
@@ -66,12 +72,12 @@ pub unsafe fn strftime<W: Write>(toplevel: bool, mut w: &mut W, maxsize: usize,
|
|
"September",
|
|
"September",
|
|
"October",
|
|
"October",
|
|
"November",
|
|
"November",
|
|
- "December"
|
|
|
|
|
|
+ "December",
|
|
];
|
|
];
|
|
|
|
|
|
while *format != 0 {
|
|
while *format != 0 {
|
|
if *format as u8 != b'%' {
|
|
if *format as u8 != b'%' {
|
|
- w!(byte *format as u8);
|
|
|
|
|
|
+ w!(byte(*format as u8));
|
|
format = format.offset(1);
|
|
format = format.offset(1);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -98,7 +104,7 @@ pub unsafe fn strftime<W: Write>(toplevel: bool, mut w: &mut W, maxsize: usize,
|
|
year += 1;
|
|
year += 1;
|
|
}
|
|
}
|
|
w!("{:02}", year + 19);
|
|
w!("{:02}", year + 19);
|
|
- },
|
|
|
|
|
|
+ }
|
|
b'd' => w!("{:02}", (*t).tm_mday),
|
|
b'd' => w!("{:02}", (*t).tm_mday),
|
|
b'D' => w!(recurse "%m/%d/%y"),
|
|
b'D' => w!(recurse "%m/%d/%y"),
|
|
b'e' => w!("{:2}", (*t).tm_mday),
|
|
b'e' => w!("{:2}", (*t).tm_mday),
|
|
@@ -129,9 +135,9 @@ pub unsafe fn strftime<W: Write>(toplevel: bool, mut w: &mut W, maxsize: usize,
|
|
b'y' => w!("{:02}", (*t).tm_year % 100),
|
|
b'y' => w!("{:02}", (*t).tm_year % 100),
|
|
b'Y' => w!("{}", (*t).tm_year + 1900),
|
|
b'Y' => w!("{}", (*t).tm_year + 1900),
|
|
b'z' => w!("+0000"), // TODO
|
|
b'z' => w!("+0000"), // TODO
|
|
- b'Z' => w!("UTC"), // TODO
|
|
|
|
|
|
+ b'Z' => w!("UTC"), // TODO
|
|
b'+' => w!(recurse "%a %b %d %T %Z %Y"),
|
|
b'+' => w!(recurse "%a %b %d %T %Z %Y"),
|
|
- _ => return 0
|
|
|
|
|
|
+ _ => return 0,
|
|
}
|
|
}
|
|
|
|
|
|
format = format.offset(1);
|
|
format = format.offset(1);
|