Fix compiler to have padding zeros in output

This commit is contained in:
Matthias Beyer 2017-05-21 15:28:50 +02:00
parent fc8fd9fecc
commit 469511918a

View file

@ -64,7 +64,7 @@ impl DatePathCompiler {
let mut s = format!("{}/", module_name); let mut s = format!("{}/", module_name);
if self.accuracy.has_year_accuracy() /* always true */ { if self.accuracy.has_year_accuracy() /* always true */ {
s.push_str(&format!("{}", datetime.year())); s.push_str(&format!("{:04}", datetime.year()));
} }
if self.accuracy.has_month_accuracy() { if self.accuracy.has_month_accuracy() {
@ -73,7 +73,7 @@ impl DatePathCompiler {
| Format::DaysAreFolder | Format::DaysAreFolder
| Format::MonthIsFolder | Format::MonthIsFolder
| Format::YearIsFolder | Format::YearIsFolder
=> s.push_str(&format!("/{}", datetime.month())), => s.push_str(&format!("/{:02}", datetime.month())),
} }
} }
@ -82,9 +82,9 @@ impl DatePathCompiler {
Format::ElementIsFolder Format::ElementIsFolder
| Format::DaysAreFolder | Format::DaysAreFolder
| Format::MonthIsFolder | Format::MonthIsFolder
=> s.push_str(&format!("/{}", datetime.day())), => s.push_str(&format!("/{:02}", datetime.day())),
Format::YearIsFolder Format::YearIsFolder
=> s.push_str(&format!("-{}", datetime.day())), => s.push_str(&format!("-{:02}", datetime.day())),
} }
} }
@ -92,32 +92,32 @@ impl DatePathCompiler {
match self.format { match self.format {
Format::ElementIsFolder Format::ElementIsFolder
| Format::DaysAreFolder | Format::DaysAreFolder
=> s.push_str(&format!("/{}", datetime.hour())), => s.push_str(&format!("/{:02}", datetime.hour())),
Format::YearIsFolder Format::YearIsFolder
| Format::MonthIsFolder | Format::MonthIsFolder
=> s.push_str(&format!("-{}", datetime.hour())), => s.push_str(&format!("-{:02}", datetime.hour())),
} }
} }
if self.accuracy.has_minute_accuracy() { if self.accuracy.has_minute_accuracy() {
match self.format { match self.format {
Format::ElementIsFolder Format::ElementIsFolder
=> s.push_str(&format!("/{}", datetime.minute())), => s.push_str(&format!("/{:02}", datetime.minute())),
Format::YearIsFolder Format::YearIsFolder
| Format::MonthIsFolder | Format::MonthIsFolder
| Format::DaysAreFolder | Format::DaysAreFolder
=> s.push_str(&format!("-{}", datetime.minute())), => s.push_str(&format!("-{:02}", datetime.minute())),
} }
} }
if self.accuracy.has_second_accuracy() { if self.accuracy.has_second_accuracy() {
match self.format { match self.format {
Format::ElementIsFolder Format::ElementIsFolder
=> s.push_str(&format!("/{}", datetime.second())), => s.push_str(&format!("/{:02}", datetime.second())),
Format::YearIsFolder Format::YearIsFolder
| Format::MonthIsFolder | Format::MonthIsFolder
| Format::DaysAreFolder | Format::DaysAreFolder
=> s.push_str(&format!("-{}", datetime.second())), => s.push_str(&format!("-{:02}", datetime.second())),
} }
} }