Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1cc1fc6
Add time namespace with clock and timestamp functions
zendrx Jul 20, 2026
d1a60a3
Implement time functions in buzz_time.zig
zendrx Jul 20, 2026
ea8797b
Add time module tests for various functionalities
zendrx Jul 20, 2026
27fc6b9
Add support for buzz_time.zig in static libraries
zendrx Jul 20, 2026
a898223
Update time.buzz
zendrx Jul 20, 2026
47ca54d
Ensure formatted string is not empty in tests
zendrx Jul 21, 2026
6a26b36
Refactor time.buzz test cases for improved clarity
zendrx Jul 21, 2026
c604303
Fix typo in export declaration for now function
zendrx Jul 21, 2026
634c46a
Refactor time functions to use updated API calls
zendrx Jul 21, 2026
d7dcdec
Simplify push of milliseconds to Buzz API
zendrx Jul 21, 2026
483b4e2
Fix function declaration for timeNow
zendrx Jul 21, 2026
9852dc1
Change var to final in time.buzz tests
zendrx Jul 21, 2026
36e9f05
Merge branch 'buzz-language:main' into time-feature
zendrx Jul 24, 2026
e8bddcb
Refactor assertions for better readability
zendrx Jul 24, 2026
b2604fe
Change CI workflow branch to 'time-feature'
zendrx Jul 24, 2026
dcdf11b
Fix indentation for workflow_dispatch in ci.yaml
zendrx Jul 24, 2026
64a0434
Fix syntax error in buzz_time.zig
zendrx Jul 24, 2026
02c3690
Add 'time' header to static_headers.zig
zendrx Jul 24, 2026
9e26bf1
Fix header reference for time in static libraries
zendrx Jul 24, 2026
9dadc95
Fix formatting of nanos calculation in buzz_time.zig
zendrx Jul 24, 2026
39ed452
Fix formatting of timestamp in buzz_time.zig
zendrx Jul 24, 2026
e1081e9
fix: Root default values on the stack to prevent bad GC sweep
giann Jul 24, 2026
9496c1b
Fix argument order in Clock.now calls
zendrx Jul 24, 2026
e828709
Remove unnecessary complex format/parse
zendrx Jul 24, 2026
5421f86
Refactor time.buzz to adjust function exports
zendrx Jul 24, 2026
b1207a2
Merge branch 'buzz-language:main' into time-feature
zendrx Jul 24, 2026
4648015
Refactor time tests to add monotonic and CPU checks
zendrx Jul 24, 2026
7eaef1c
Refactor time tests to add monotonic and CPU checks
zendrx Jul 25, 2026
658580d
Merge branch 'time-feature' of https://github.com/zendrx/buzz into ti…
zendrx Jul 27, 2026
1562f66
Update static_headers.zig
zendrx Jul 27, 2026
4c9b016
Merge branch 'main' into main
zendrx Aug 20, 2026
46cb94c
all tests passing
zendrx Aug 20, 2026
50959b4
Change CI trigger branch from 'time-feature' to 'main'
zendrx Aug 20, 2026
3447258
Remove workflow_dispatch from CI workflow
zendrx Aug 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/lib/buzz_time.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const api = @import("buzz_api.zig");
const std = @import("std");

pub export fn timeNow(ctx: *api.NativeCtx) callconv(.c) c_int {
const ts = std.Io.Timestamp.now(ctx.getIo(), .real);
const ms = ts.toMilliseconds();
ctx.vm.bz_push(.fromDouble(@floatFromInt(ms)));
return 1;
}

pub export fn timeMonotonic(ctx: *api.NativeCtx) callconv(.c) c_int {
const ts = std.Io.Timestamp.now(ctx.getIo(), .awake);
const ms = ts.toMilliseconds();
ctx.vm.bz_push(.fromDouble(@floatFromInt(ms)));
return 1;
}

pub export fn timeCpu(ctx: *api.NativeCtx) callconv(.c) c_int {
const ts = std.Io.Timestamp.now(ctx.getIo(), .cpu_process);
const ms = ts.toMilliseconds();
ctx.vm.bz_push(.fromDouble(@floatFromInt(ms)));
return 1;
}

pub const library = api.BuzzApi(
"time",
&.{
&.{ "now", timeNow },
&.{ "monotonic", timeMonotonic },
&.{ "cpu", timeCpu },
},
){};
2 changes: 2 additions & 0 deletions src/lib/static_headers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub const math = Header{ .name = "math", .path = "math.buzz" };
pub const os = Header{ .name = "os", .path = "os.buzz" };
pub const serialize = Header{ .name = "serialize", .path = "serialize.buzz" };
pub const std = Header{ .name = "std", .path = "std.buzz" };
pub const time = Header{ .name = "time", .path = "time.buzz" };
pub const testing = Header{ .name = "test", .path = "testing.buzz" };

/// Buzz headers bundled with the compiler/runtime and installed for tooling.
Expand All @@ -41,4 +42,5 @@ pub const all = [_]Header{
serialize,
std,
testing,
time,
};
2 changes: 2 additions & 0 deletions src/lib/static_libraries.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub const all = [_]Library{
.{ .header = static_headers.os, .zig_path = "buzz_os.zig", .wasm_native = false },
.{ .header = static_headers.serialize, .zig_path = "buzz_serialize.zig", .wasm_native = true },
.{ .header = static_headers.std, .zig_path = "buzz_std.zig", .wasm_native = true },
.{ .header = static_headers.time, .zig_path = "buzz_time.zig", .wasm_native = false },
.{ .header = static_headers.testing, .zig_path = null, .wasm_native = false },
};

Expand Down Expand Up @@ -98,6 +99,7 @@ fn nativeMethods(comptime library: Library) std.StaticStringMap(buzz_api.NativeF
if (std.mem.eql(u8, zig_path, "buzz_os.zig")) return checkedNativeMethods(library, @import("buzz_os.zig").library);
if (std.mem.eql(u8, zig_path, "buzz_serialize.zig")) return checkedNativeMethods(library, @import("buzz_serialize.zig").library);
if (std.mem.eql(u8, zig_path, "buzz_std.zig")) return checkedNativeMethods(library, @import("buzz_std.zig").library);
if (std.mem.eql(u8, zig_path, "buzz_time.zig")) return checkedNativeMethods(library, @import("buzz_time.zig").library);

@compileError("unknown native library path: " ++ zig_path);
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/time.buzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace time;

import "buzz:errors";

/// Real-time (wall-clock) in milliseconds since Unix epoch
export extern fun now() > double;

/// Monotonic clock in milliseconds (never goes backwards for intervals)
export extern fun monotonic() > double;

/// Cpu time used by the current process in milliseconds
export extern fun cpu() > double !> errors\UnexpectedError;
29 changes: 29 additions & 0 deletions tests/behavior/time.buzz
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "buzz:std";
import "buzz:time";
import "buzz:os" as os;

test "now returns a positive number" {
final now = time\now();
std\assert(
now > 0,
message: "now should be greater than 0"
);
}

test "monotonic increases" {
final start = time\monotonic();
os\sleep(12.0);
final end = time\monotonic();
std\assert(
end > start,
message: "monotonic should increase after sleep"
);
}

test "cpu returns a positive number" {
final cpu = time\cpu();
std\assert(
cpu >= 0,
message: "cpu time should be >= 0"
);
}