Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

DurationFormatters

Appends an exact duration count and its canonical reduced unit.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.format

import std.format;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

fn

pub const fn FormatTo<Rep, const Numerator: u64, const Denominator: u64>(
    Value: readonly Duration<Rep, Numerator, Denominator>&, Builder: mut StringBuilder&) -> void
    where Rep: Data, DurationCount, Formattable

Appends an exact duration count and its canonical reduced unit.

Count formatting composes the statically selected Formattable representation; it does not convert units, narrow counts or create an intermediate String. Known periods print a canonical suffix. Custom periods print (N/D s) so the per-count scale remains explicit. Borrowed inputs do not escape. Only Builder is mutated; callers synchronize its use and observe sticky allocation failure through checked finalization. Runtime builder growth may allocate. Rep: Copyable Defaultable count with a structural Formattable witness. Numerator: Positive compile-time seconds numerator. Denominator: Positive compile-time seconds denominator. Value: Readonly duration borrowed for this entire formatting call. Builder: Writable UTF-8 destination; mutation invalidates prior views. Return: No value; destination finalization reports sticky allocation failure.

Example

module example.duration_formatting;
from std.format import FormatTo;
from std.text import StringBuilder;
from std.time import Duration, Milliseconds, Years;
fn Main() -> i32 {
    var Builder = StringBuilder();
    FormatTo(Milliseconds.Create(2250), Builder);
    Builder.Append("; ");
    FormatTo(Years.Create(2), Builder);
    Builder.Append("; ");
    FormatTo(Duration<i64, 6, 4>.Create(7), Builder);
    switch Builder.TryFinalize() {
        case .Ok { Value = Text } => {
            if Text.View != "2250 ms; 2 years; 7 (3/2 s)" { return 1; }
        }
        case .Err => return 2;
    }
    return 0;
}
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library