feat: Support date (#11)
parent
3dc2a59ede
commit
a27396e262
|
@ -23,6 +23,16 @@ impl CoreProps {
|
|||
pub(crate) fn new(config: CorePropsConfig) -> CoreProps {
|
||||
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 {
|
||||
|
|
|
@ -18,6 +18,16 @@ impl DocProps {
|
|||
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 {
|
||||
XMLDocProps {
|
||||
app: self.app.build(),
|
||||
|
|
|
@ -90,6 +90,16 @@ impl Docx {
|
|||
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 {
|
||||
self.update_comments();
|
||||
XMLDocx {
|
||||
|
|
|
@ -402,3 +402,16 @@ pub fn vanish() -> Result<(), DocxError> {
|
|||
.pack(file)?;
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue