Function printDurationSigned [src]
Prototype
pub fn printDurationSigned(w: *Writer, ns: i64) Error!void
Parameters
w: *Writer
ns: i64
Possible Errors
See the Writer
implementation for detailed diagnostics.
Example
test printDurationSigned {
try testDurationCaseSigned("0ns", 0);
try testDurationCaseSigned("1ns", 1);
try testDurationCaseSigned("-1ns", -(1));
try testDurationCaseSigned("999ns", std.time.ns_per_us - 1);
try testDurationCaseSigned("-999ns", -(std.time.ns_per_us - 1));
try testDurationCaseSigned("1us", std.time.ns_per_us);
try testDurationCaseSigned("-1us", -(std.time.ns_per_us));
try testDurationCaseSigned("1.45us", 1450);
try testDurationCaseSigned("-1.45us", -(1450));
try testDurationCaseSigned("1.5us", 3 * std.time.ns_per_us / 2);
try testDurationCaseSigned("-1.5us", -(3 * std.time.ns_per_us / 2));
try testDurationCaseSigned("14.5us", 14500);
try testDurationCaseSigned("-14.5us", -(14500));
try testDurationCaseSigned("145us", 145000);
try testDurationCaseSigned("-145us", -(145000));
try testDurationCaseSigned("999.999us", std.time.ns_per_ms - 1);
try testDurationCaseSigned("-999.999us", -(std.time.ns_per_ms - 1));
try testDurationCaseSigned("1ms", std.time.ns_per_ms + 1);
try testDurationCaseSigned("-1ms", -(std.time.ns_per_ms + 1));
try testDurationCaseSigned("1.5ms", 3 * std.time.ns_per_ms / 2);
try testDurationCaseSigned("-1.5ms", -(3 * std.time.ns_per_ms / 2));
try testDurationCaseSigned("1.11ms", 1110000);
try testDurationCaseSigned("-1.11ms", -(1110000));
try testDurationCaseSigned("1.111ms", 1111000);
try testDurationCaseSigned("-1.111ms", -(1111000));
try testDurationCaseSigned("1.111ms", 1111100);
try testDurationCaseSigned("-1.111ms", -(1111100));
try testDurationCaseSigned("999.999ms", std.time.ns_per_s - 1);
try testDurationCaseSigned("-999.999ms", -(std.time.ns_per_s - 1));
try testDurationCaseSigned("1s", std.time.ns_per_s);
try testDurationCaseSigned("-1s", -(std.time.ns_per_s));
try testDurationCaseSigned("59.999s", std.time.ns_per_min - 1);
try testDurationCaseSigned("-59.999s", -(std.time.ns_per_min - 1));
try testDurationCaseSigned("1m", std.time.ns_per_min);
try testDurationCaseSigned("-1m", -(std.time.ns_per_min));
try testDurationCaseSigned("1h", std.time.ns_per_hour);
try testDurationCaseSigned("-1h", -(std.time.ns_per_hour));
try testDurationCaseSigned("1d", std.time.ns_per_day);
try testDurationCaseSigned("-1d", -(std.time.ns_per_day));
try testDurationCaseSigned("1w", std.time.ns_per_week);
try testDurationCaseSigned("-1w", -(std.time.ns_per_week));
try testDurationCaseSigned("1y", 365 * std.time.ns_per_day);
try testDurationCaseSigned("-1y", -(365 * std.time.ns_per_day));
try testDurationCaseSigned("1y52w23h59m59.999s", 730 * std.time.ns_per_day - 1); // 365d = 52w1d
try testDurationCaseSigned("-1y52w23h59m59.999s", -(730 * std.time.ns_per_day - 1)); // 365d = 52w1d
try testDurationCaseSigned("1y1h1.001s", 365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_s + std.time.ns_per_ms);
try testDurationCaseSigned("-1y1h1.001s", -(365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_s + std.time.ns_per_ms));
try testDurationCaseSigned("1y1h1s", 365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_s + 999 * std.time.ns_per_us);
try testDurationCaseSigned("-1y1h1s", -(365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_s + 999 * std.time.ns_per_us));
try testDurationCaseSigned("1y1h999.999us", 365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms - 1);
try testDurationCaseSigned("-1y1h999.999us", -(365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms - 1));
try testDurationCaseSigned("1y1h1ms", 365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms);
try testDurationCaseSigned("-1y1h1ms", -(365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms));
try testDurationCaseSigned("1y1h1ms", 365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms + 1);
try testDurationCaseSigned("-1y1h1ms", -(365 * std.time.ns_per_day + std.time.ns_per_hour + std.time.ns_per_ms + 1));
try testDurationCaseSigned("1y1m999ns", 365 * std.time.ns_per_day + std.time.ns_per_min + 999);
try testDurationCaseSigned("-1y1m999ns", -(365 * std.time.ns_per_day + std.time.ns_per_min + 999));
try testDurationCaseSigned("292y24w3d23h47m16.854s", std.math.maxInt(i64));
try testDurationCaseSigned("-292y24w3d23h47m16.854s", std.math.minInt(i64) + 1);
try testDurationCaseSigned("-292y24w3d23h47m16.854s", std.math.minInt(i64));
try testing.expectFmt("=======0ns", "{D:=>10}", .{0});
try testing.expectFmt("1ns=======", "{D:=<10}", .{1});
try testing.expectFmt("-1ns======", "{D:=<10}", .{-(1)});
try testing.expectFmt(" -999ns ", "{D:^10}", .{-(std.time.ns_per_us - 1)});
}
Source
pub fn printDurationSigned(w: *Writer, ns: i64) Error!void {
if (ns < 0) try w.writeByte('-');
return w.printDurationUnsigned(@abs(ns));
}