feat: Support date (#11)

main
bokuweb 2019-12-15 00:39:15 +09:00 committed by GitHub
parent 3dc2a59ede
commit a27396e262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 0 deletions

View File

@ -23,6 +23,16 @@ impl CoreProps {
pub(crate) fn new(config: CorePropsConfig) -> CoreProps { pub(crate) fn new(config: CorePropsConfig) -> CoreProps {
CoreProps { config } CoreProps { config }
} }
pub fn created_at(mut self, date: &str) -> Self {
self.config.created = Some(date.to_owned());
self
}
pub fn updated_at(mut self, date: &str) -> Self {
self.config.modified = Some(date.to_owned());
self
}
} }
impl CorePropsConfig { impl CorePropsConfig {

View File

@ -18,6 +18,16 @@ impl DocProps {
DocProps { app, core } DocProps { app, core }
} }
pub fn created_at(mut self, date: &str) -> Self {
self.core = self.core.created_at(date);
self
}
pub fn updated_at(mut self, date: &str) -> Self {
self.core = self.core.updated_at(date);
self
}
pub(crate) fn build(&self) -> XMLDocProps { pub(crate) fn build(&self) -> XMLDocProps {
XMLDocProps { XMLDocProps {
app: self.app.build(), app: self.app.build(),

View File

@ -90,6 +90,16 @@ impl Docx {
self self
} }
pub fn created_at(mut self, date: &str) -> Self {
self.doc_props = self.doc_props.created_at(date);
self
}
pub fn updated_at(mut self, date: &str) -> Self {
self.doc_props = self.doc_props.updated_at(date);
self
}
pub fn build(&mut self) -> XMLDocx { pub fn build(&mut self) -> XMLDocx {
self.update_comments(); self.update_comments();
XMLDocx { XMLDocx {

View File

@ -402,3 +402,16 @@ pub fn vanish() -> Result<(), DocxError> {
.pack(file)?; .pack(file)?;
Ok(()) Ok(())
} }
#[test]
pub fn date() -> Result<(), DocxError> {
let path = std::path::Path::new("./tests/output/date.docx");
let file = std::fs::File::create(&path).unwrap();
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.created_at("2019-01-01T00:00:00Z")
.updated_at("2019-01-02T10:00:00Z")
.build()
.pack(file)?;
Ok(())
}