mirror of
https://github.com/zyllian/webdog.git
synced 2025-07-01 02:41:58 -07:00
implement custom timestamp formats for resources, resolves #15
This commit is contained in:
parent
0233bf0dad
commit
5b09813f24
6 changed files with 62 additions and 38 deletions
|
@ -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)?)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue