implement custom timestamp formats for resources, resolves #15

This commit is contained in:
zyl 2024-11-13 14:52:36 -08:00
parent 0233bf0dad
commit 5b09813f24
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
6 changed files with 62 additions and 38 deletions

View file

@ -2,6 +2,8 @@
use std::path::Path;
use time::OffsetDateTime;
/// Simple helper to remove the contents of a directory without removing the directory itself.
pub fn remove_dir_contents(path: &Path) -> eyre::Result<()> {
for entry in path.read_dir()? {
@ -16,3 +18,9 @@ pub fn remove_dir_contents(path: &Path) -> eyre::Result<()> {
Ok(())
}
/// Helper to format a timestamp according to the given format.
pub fn format_timestamp(ts: OffsetDateTime, format: &str) -> eyre::Result<String> {
let fmt = time::format_description::parse_borrowed::<2>(format)?;
Ok(ts.format(&fmt)?)
}