diff --git a/src/shell/interpreter.zig b/src/shell/interpreter.zig index 689b99520e..0c0261eb3d 100644 --- a/src/shell/interpreter.zig +++ b/src/shell/interpreter.zig @@ -10520,16 +10520,44 @@ pub const Interpreter = struct { var total_seconds: f64 = 0; while (iter.next()) |arg| { invalid_interval: { - const trimmed = bun.strings.trimLeft(bun.sliceTo(arg, 0), " "); + var trimmed: string = bun.strings.trimLeft(bun.sliceTo(arg, 0), " "); if (trimmed.len == 0 or trimmed[0] == '-') { break :invalid_interval; } - const seconds = bun.fmt.parseFloat(f64, trimmed) catch { + const maybe_unit: ?enum { + seconds, + minutes, + hours, + days, + + pub fn apply(unit: @This(), value: f64) f64 { + return switch (unit) { + .seconds => value, + .minutes => value * 60, + .hours => value * 60 * 60, + .days => value * 60 * 60 * 24, + }; + } + } = switch (trimmed[trimmed.len - 1]) { + 's' => .seconds, + 'm' => .minutes, + 'h' => .hours, + 'd' => .days, + else => null, + }; + + if (maybe_unit != null) { + trimmed = trimmed[0 .. trimmed.len - 1]; + } + + const value = bun.fmt.parseFloat(f64, trimmed) catch { break :invalid_interval; }; + const seconds = if (maybe_unit) |unit| unit.apply(value) else value; + if (std.math.isInf(seconds)) { // if positive infinity is seen, set total seconds to `-1`. // continue iterating to catch invalid args diff --git a/test/js/bun/shell/test_builder.ts b/test/js/bun/shell/test_builder.ts index 7728a0b5c9..8f1697b131 100644 --- a/test/js/bun/shell/test_builder.ts +++ b/test/js/bun/shell/test_builder.ts @@ -222,7 +222,7 @@ export function createTestBuilder(path: string) { async doChecks(stdout: Buffer, stderr: Buffer, exitCode: number, durationMs: number): Promise { const tempdir = this.tempdir || "NO_TEMP_DIR"; if (this._expectedDuration !== undefined) { - expect(durationMs).toBeGreaterThanOrEqual(this._expectedDuration); + expect(durationMs >= this._expectedDuration && durationMs <= this._expectedDuration + 200).toBeTrue(); } if (this.expected_stdout !== undefined) { if (typeof this.expected_stdout === "string") {