Skip to content

Support time components in date_format #240

@hulr

Description

@hulr

Thank you very much for creating IWE! It's exactly the tool I was looking for to improve my workflow.

I would like to use the minute (%M) and hour (%H) number in date_format. The config would look something like this:

[library]
path = ""
date_format = "%Y%m%d%M%H"

[templates.default]
key_template = "{{today}} {{title}}"
document_template = "# {{today}} {{title}}"

Currently, when trying to create a new document with iwe new and the config from above I get the following error:

$ iwe --version
iwe 0.0.60

$ RUST_BACKTRACE=full iwe new "test"

thread 'main' (8290) panicked at /build/rustc-1.93.0-src/library/alloc/src/string.rs:2889:14:
a Display implementation returned an error unexpectedly: Error
stack backtrace:
   0:     0x5562a431ffab - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4abbbc3d9ecfa86c
   1:     0x5562a433c507 - core::fmt::write::he00acd824749ac8b
   2:     0x5562a42e0b42 - std::io::default_write_fmt::h43bad14283851991
   3:     0x5562a43197b2 - std::sys::backtrace::BacktraceLock::print::h79d51edf656c8655
   4:     0x5562a42e347c - std::panicking::default_hook::{{closure}}::hfdec67f3f6a8e696
   5:     0x5562a42e3315 - std::panicking::default_hook::h8ddbbb7d400ff4fb
   6:     0x5562a42e35fb - std::panicking::panic_with_hook::ha4edca3cf4c438c6
   7:     0x5562a43199a8 - std::panicking::panic_handler::{{closure}}::h114a630d885f2c13
   8:     0x5562a43198b9 - std::sys::backtrace::__rust_end_short_backtrace::hf6231de488bca95f
   9:     0x5562a42e035d - __rustc[881eff9798cad629]::rust_begin_unwind
  10:     0x5562a3f7063c - core::panicking::panic_fmt::h7509f5fc1f52ade1
  11:     0x5562a3f70742 - core::result::unwrap_failed::h4811fcb6dcdb23ec
  12:     0x5562a3fb68d8 - iwe::new::DocumentCreator::create::hb69c6c1ed1c53f9a
  13:     0x5562a3f7c9ce - iwe::main::hb53d3b5374955c2d
  14:     0x5562a3fa2ce6 - std::sys::backtrace::__rust_begin_short_backtrace::h31f2e4557eb15318
  15:     0x5562a3f9e42c - std::rt::lang_start::{{closure}}::h60d4ca20d2ad014e
  16:     0x5562a42fa4f6 - std::rt::lang_start_internal::h4a4e50345e9944f8
  17:     0x5562a3f8695d - main
  18:     0x7fe24c42b285 - __libc_start_call_main
  19:     0x7fe24c42b338 - __libc_start_main_alias_2
  20:     0x5562a3f70775 - _start
  21:                0x0 - <unknown>

I think this is because IWE is using NaiveDate which does not have the time components.

iwe/crates/iwe/src/new.rs

Lines 100 to 102 in c891e7c

let date = Local::now().date_naive();
let key_today = date.format(&key_date_format).to_string();
let markdown_today = date.format(&markdown_date_format).to_string();

Would it be possible to support the time components (hour and minute number) in date_format for both library and markdown settings (f.e. using NaiveDateTime)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions