Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

DurationMagnitude

Preserves exact integer or finite IEEE count facts for checked time conversion.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.time

import std.time;

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

DurationMagnitude

pub struct DurationMagnitude

Preserves exact integer or finite IEEE count facts for checked time conversion.

This value owns no allocation. Public integer zero is canonicalized to nonnegative; private IEEE facts retain signed zero. Signed minimum can be represented without trying to negate it in its signed type. Immutable concurrent access is safe. Generic duration conversion uses these facts without forcing large time units into a smaller representation. Declarative defaults form canonical nonnegative integer zero. Named factories preserve integer normalization and internal IEEE signed-zero facts separately.

Example

module example.duration_magnitude_factory;
from std.time import DurationMagnitude, DurationPeriod;
fn Main() -> i32 {
    let Zero = DurationMagnitude.FromInteger(0, true);
    if Zero.Magnitude != 0 || Zero.Negative { return 1; }
    let Empty = default(DurationMagnitude);
    if Empty.Magnitude != 0 || Empty.Negative { return 2; }
    let Negative = DurationMagnitude.FromInteger(2500, true);
    let Milliseconds = switch DurationPeriod.TryCreate(1, 1000) {
        case .Ok { Value = Value } => break Value;
        case .Err { Error = _ } => return 3;
    };
    let Scale = Milliseconds.ScaleTo(default(DurationPeriod));
    switch Scale.ConvertMagnitude(Negative.Magnitude, Negative.Negative, .Floor) {
        case .Ok { Value = Value } => { if Value != 3 { return 4; } }
        case .Err { Error = _ } => return 5;
    }
    switch Scale.ConvertMagnitude(Negative.Magnitude, Negative.Negative, .NearestEven) {
        case .Ok { Value = Value } => { if Value != 2 { return 6; } }
        case .Err { Error = _ } => return 7;
    }
    return 0;
}

DurationMagnitude.Magnitude

pub Magnitude: u128;

Stores an exact unsigned count magnitude.

DurationMagnitude.Negative

pub Negative: bool;

Reports the source sign, including internally encoded IEEE negative zero.

DurationMagnitude.fn

pub static const fn FromInteger(Magnitude: u128, Negative: bool) -> DurationMagnitude

Copies an integer count magnitude and canonicalizes zero's sign. Magnitude: Exact unsigned integer count magnitude. Negative: True for negative input; ignored for zero. Return: Independent count facts with zero binary exponent; no allocation, retained borrow or synchronization. Signed minimum magnitudes are valid.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library