@@ -1380,13 +1380,8 @@ test fmtDuration {
1380
1380
}
1381
1381
1382
1382
fn formatDurationSigned (ns : i64 , comptime fmt : []const u8 , options : std.fmt.FormatOptions , writer : anytype ) ! void {
1383
- if (ns < 0 ) {
1384
- const data = FormatDurationData { .ns = @as (u64 , @intCast (- ns )), .negative = true };
1385
- try formatDuration (data , fmt , options , writer );
1386
- } else {
1387
- const data = FormatDurationData { .ns = @as (u64 , @intCast (ns )) };
1388
- try formatDuration (data , fmt , options , writer );
1389
- }
1383
+ const data = FormatDurationData { .ns = @abs (ns ), .negative = ns < 0 };
1384
+ try formatDuration (data , fmt , options , writer );
1390
1385
}
1391
1386
1392
1387
/// Return a Formatter for number of nanoseconds according to its signed magnitude:
@@ -1457,6 +1452,7 @@ test fmtDurationSigned {
1457
1452
.{ .s = "-1y1m999ns" , .d = - (365 * std .time .ns_per_day + std .time .ns_per_min + 999 ) },
1458
1453
.{ .s = "292y24w3d23h47m16.854s" , .d = math .maxInt (i64 ) },
1459
1454
.{ .s = "-292y24w3d23h47m16.854s" , .d = math .minInt (i64 ) + 1 },
1455
+ .{ .s = "-292y24w3d23h47m16.854s" , .d = math .minInt (i64 ) },
1460
1456
}) | tc | {
1461
1457
const slice = try bufPrint (& buf , "{}" , .{fmtDurationSigned (tc .d )});
1462
1458
try std .testing .expectEqualStrings (tc .s , slice );
0 commit comments