1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#[macro_use] extern crate quick_error;
use chrono::{ Local,prelude::*, };
quick_error! {
#[derive(Debug)]
pub enum ParseError {
Format(m: String) {
display("Format error: {}", m)
}
}
}
enum SimpleDateFormatPart {
Year,
Month,
Day,
Hour,
Minute,
Second,
Literal(String),
}
pub struct SimpleDateFormat {
parts: Vec<SimpleDateFormatPart>,
}
impl SimpleDateFormat {
fn format_local(&self, date_time: &DateTime<Local>) -> String {
let mut ret = String::with_capacity(512);
ret.push_str(&format!("{}", date_time.year()));
ret.push('-');
ret.push_str(&format!("{}", date_time.month()));
ret.push('-');
ret.push_str(&format!("{}", date_time.day()));
ret
}
}
pub fn fmt(f: &str) -> Result<SimpleDateFormat, ParseError> {
Ok(SimpleDateFormat{ parts: vec![] })
}
#[test]
fn it_works() {
println!("test output: {}", fmt("").unwrap().format_local(&Local::now()));
assert_eq!(2 + 2, 4);
}