use chrono::DateTime;
use ironcalc_base::{
new_empty::{APPLICATION, APP_VERSION, IRONCALC_USER},
types::Workbook,
};
use crate::error::XlsxError;
// Application-Defined File Properties part
pub(crate) fn get_app_xml(_: &Workbook) -> String {
// contains application name and version
// The next few are not needed:
// security. It is password protected (not implemented)
// Scale
// Titles of parts
format!(
"
\
{}\
{}\
",
APPLICATION, APP_VERSION
)
}
// Core File Properties part
pub(crate) fn get_core_xml(workbook: &Workbook, milliseconds: i64) -> Result {
// contains the name of the creator, last modified and date
let metadata = &workbook.metadata;
let creator = metadata.creator.to_string();
let last_modified_by = IRONCALC_USER.to_string();
let created = metadata.created.to_string();
// FIXME add now
let seconds = milliseconds / 1000;
let dt = match DateTime::from_timestamp(seconds, 0) {
Some(s) => s,
None => {
return Err(XlsxError::Xml(format!(
"Invalid timestamp: {}",
milliseconds
)))
}
};
let last_modified = dt.format("%Y-%m-%dT%H:%M:%SZ").to_string();
Ok(format!(
"
\
\
{}\
\
\
{}\
\
{}\
{}\
\
\
",
creator, last_modified_by, created, last_modified
))
}