Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ tempfile = "3.8.0"
ninja_env = { path = "ninja_env" }
shell-quote = { version = "0.7.2", default-features = false, features = ["sh"] }
shlex = "1.3.0"
time = { version = "0.3.44", features = ["formatting", "macros", "parsing", "serde"] }

[build-dependencies]
clap = { version = "4.5.0", features = ["derive"] }
clap_mangen = "0.2.29"
time = { version = "0.3.42", features = ["formatting"] }
time = { version = "0.3.44", features = ["formatting"] }

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
Expand Down
16 changes: 16 additions & 0 deletions docs/netsuke-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,22 @@ be marked `pure` if safe for caching or `impure` otherwise.
| `now()` | function | Current `datetime` (UTC by default) |
| `timedelta(**kwargs)` | function | Convenience creator for `age` comparisons |

The `now()` helper produces an object that renders as an ISO 8601
timestamp and exposes `iso8601`, `unix_timestamp`, and `offset` accessors so
templates can serialize or compare values without string parsing. It defaults
to UTC but accepts an `offset="+HH:MM"` keyword argument that re-bases the
captured time on another fixed offset. Time is captured lazily when the helper
executes so behaviour remains deterministic during a render.

`timedelta(**kwargs)` constructs a duration object that renders using the
ISO 8601 duration grammar (for example, `P1DT2H30M5.75025S`). The helper
accepts integer keyword arguments `weeks`, `days`, `hours`, `minutes`,
`seconds`, `milliseconds`, `microseconds`, and `nanoseconds`, allowing callers
to describe durations at nanosecond precision. Arguments may be negative, but
overflow or non-integer inputs raise `InvalidOperation` errors so templates
cannot silently wrap. The resulting object exposes `.iso8601`, `.seconds`, and
`.nanoseconds` attributes for downstream predicates.

##### Example usage

```jinja
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ library, and CLI ergonomics.
- [ ] Implement the network and command functions/filters (fetch, shell,
grep), ensuring shell marks templates as impure to disable caching.

- [ ] Implement the time helpers (`now`, `timedelta`).
- [x] Implement the time helpers (`now`, `timedelta`).

- [ ] **CLI and Feature Completeness:**

Expand Down
2 changes: 2 additions & 0 deletions src/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

mod collections;
mod path;
mod time;

use camino::Utf8Path;
use cap_std::fs;
Expand Down Expand Up @@ -39,6 +40,7 @@ pub fn register(env: &mut Environment<'_>) {
register_file_tests(env);
path::register_filters(env);
collections::register_filters(env);
time::register_functions(env);
}

fn register_file_tests(env: &mut Environment<'_>) {
Expand Down
Loading
Loading