add day,hour,sec
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@@ -18,10 +18,11 @@ enum SimpleDateFormatPart {
|
|||||||
YearLower(usize),
|
YearLower(usize),
|
||||||
YearUpper(usize),
|
YearUpper(usize),
|
||||||
Month(usize),
|
Month(usize),
|
||||||
Day,
|
Day(usize),
|
||||||
Hour,
|
HourLower(usize),
|
||||||
|
HourUpper(usize),
|
||||||
Minute(usize),
|
Minute(usize),
|
||||||
Second,
|
Second(usize),
|
||||||
LiteralChar(char),
|
LiteralChar(char),
|
||||||
Literal(String),
|
Literal(String),
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,11 @@ impl SimpleDateFormat {
|
|||||||
} else {
|
} else {
|
||||||
ret.push_str(format_month(date_time.month(), *cnt));
|
ret.push_str(format_month(date_time.month(), *cnt));
|
||||||
},
|
},
|
||||||
|
SimpleDateFormatPart::Day(cnt) => ret.push_str(&format_str(date_time.day() as i32, *cnt)),
|
||||||
|
SimpleDateFormatPart::HourLower(cnt) => ret.push_str(&format_str(date_time.hour12().1 as i32, *cnt)),
|
||||||
|
SimpleDateFormatPart::HourUpper(cnt) => ret.push_str(&format_str(date_time.hour() as i32, *cnt)),
|
||||||
SimpleDateFormatPart::Minute(cnt) => ret.push_str(&format_str(date_time.minute() as i32, *cnt)),
|
SimpleDateFormatPart::Minute(cnt) => ret.push_str(&format_str(date_time.minute() as i32, *cnt)),
|
||||||
|
SimpleDateFormatPart::Second(cnt) => ret.push_str(&format_str(date_time.second() as i32, *cnt)),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +87,11 @@ pub fn fmt(f: &str) -> Result<SimpleDateFormat, ParseError> {
|
|||||||
'y' => parts.push(SimpleDateFormatPart::YearLower(get_all_chars(c, &mut chars))),
|
'y' => parts.push(SimpleDateFormatPart::YearLower(get_all_chars(c, &mut chars))),
|
||||||
'Y' => parts.push(SimpleDateFormatPart::YearUpper(get_all_chars(c, &mut chars))),
|
'Y' => parts.push(SimpleDateFormatPart::YearUpper(get_all_chars(c, &mut chars))),
|
||||||
'M' => parts.push(SimpleDateFormatPart::Month(get_all_chars(c, &mut chars))),
|
'M' => parts.push(SimpleDateFormatPart::Month(get_all_chars(c, &mut chars))),
|
||||||
|
'd' => parts.push(SimpleDateFormatPart::Day(get_all_chars(c, &mut chars))),
|
||||||
|
'h' => parts.push(SimpleDateFormatPart::HourLower(get_all_chars(c, &mut chars))),
|
||||||
|
'H' => parts.push(SimpleDateFormatPart::HourUpper(get_all_chars(c, &mut chars))),
|
||||||
'm' => parts.push(SimpleDateFormatPart::Minute(get_all_chars(c, &mut chars))),
|
'm' => parts.push(SimpleDateFormatPart::Minute(get_all_chars(c, &mut chars))),
|
||||||
|
's' => parts.push(SimpleDateFormatPart::Second(get_all_chars(c, &mut chars))),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +146,7 @@ fn it_works() {
|
|||||||
// println!("test output: {}", fmt("").unwrap().format_local(&Local::now()));
|
// println!("test output: {}", fmt("").unwrap().format_local(&Local::now()));
|
||||||
|
|
||||||
println!("{:?}", fmt("y yy-mm 'mm '''"));
|
println!("{:?}", fmt("y yy-mm 'mm '''"));
|
||||||
println!("{:?}", fmt("y yy-MM mm'(-'m')' MM MMM MMMMM '[mm]'").unwrap().format_local(&Local::now()));
|
println!("{:?}", fmt("yyyy-MM-dd HH:mm:ss MMM dd, yyyy hh:mm:ss").unwrap().format_local(&Local::now()));
|
||||||
|
|
||||||
assert_eq!(2 + 2, 4);
|
assert_eq!(2 + 2, 4);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user