authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-06-19 21:10:20+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 15:20:49-07:00
logc6e2e1ae4b85fc36acc89c9a5e2673834146d628
tree23efbd861edc037dac7b05ded45b1dfb63c9c85f
parent8bd07fb1be034556874bdafb5cf895e2f941a6bc

std.fmt: fix error set of formatDuration


1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/fmt.zig+8-8
...@@ -1488,7 +1488,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s...@@ -1488,7 +1488,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
1488 var fbs = std.io.fixedBufferStream(&buf);1488 var fbs = std.io.fixedBufferStream(&buf);
1489 var buf_writer = fbs.writer();1489 var buf_writer = fbs.writer();
1490 if (data.negative) {1490 if (data.negative) {
1491 try buf_writer.writeByte('-');1491 buf_writer.writeByte('-') catch unreachable;
1492 }1492 }
14931493
1494 var ns_remaining = data.ns;1494 var ns_remaining = data.ns;
...@@ -1501,8 +1501,8 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s...@@ -1501,8 +1501,8 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
1501 }) |unit| {1501 }) |unit| {
1502 if (ns_remaining >= unit.ns) {1502 if (ns_remaining >= unit.ns) {
1503 const units = ns_remaining / unit.ns;1503 const units = ns_remaining / unit.ns;
1504 try formatInt(units, 10, .lower, .{}, buf_writer);1504 formatInt(units, 10, .lower, .{}, buf_writer) catch unreachable;
1505 try buf_writer.writeByte(unit.sep);1505 buf_writer.writeByte(unit.sep) catch unreachable;
1506 ns_remaining -= units * unit.ns;1506 ns_remaining -= units * unit.ns;
1507 if (ns_remaining == 0)1507 if (ns_remaining == 0)
1508 return formatBuf(fbs.getWritten(), options, writer);1508 return formatBuf(fbs.getWritten(), options, writer);
...@@ -1516,7 +1516,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s...@@ -1516,7 +1516,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
1516 }) |unit| {1516 }) |unit| {
1517 const kunits = ns_remaining * 1000 / unit.ns;1517 const kunits = ns_remaining * 1000 / unit.ns;
1518 if (kunits >= 1000) {1518 if (kunits >= 1000) {
1519 try formatInt(kunits / 1000, 10, .lower, .{}, buf_writer);1519 formatInt(kunits / 1000, 10, .lower, .{}, buf_writer) catch unreachable;
1520 const frac = kunits % 1000;1520 const frac = kunits % 1000;
1521 if (frac > 0) {1521 if (frac > 0) {
1522 // Write up to 3 decimal places1522 // Write up to 3 decimal places
...@@ -1526,15 +1526,15 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s...@@ -1526,15 +1526,15 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
1526 while (end > 1) : (end -= 1) {1526 while (end > 1) : (end -= 1) {
1527 if (decimal_buf[end - 1] != '0') break;1527 if (decimal_buf[end - 1] != '0') break;
1528 }1528 }
1529 try buf_writer.writeAll(decimal_buf[0..end]);1529 buf_writer.writeAll(decimal_buf[0..end]) catch unreachable;
1530 }1530 }
1531 try buf_writer.writeAll(unit.sep);1531 buf_writer.writeAll(unit.sep) catch unreachable;
1532 return formatBuf(fbs.getWritten(), options, writer);1532 return formatBuf(fbs.getWritten(), options, writer);
1533 }1533 }
1534 }1534 }
15351535
1536 try formatInt(ns_remaining, 10, .lower, .{}, buf_writer);1536 formatInt(ns_remaining, 10, .lower, .{}, buf_writer) catch unreachable;
1537 try buf_writer.writeAll("ns");1537 buf_writer.writeAll("ns") catch unreachable;
1538 return formatBuf(fbs.getWritten(), options, writer);1538 return formatBuf(fbs.getWritten(), options, writer);
1539}1539}
15401540