const std = @import("std"); const cron = @import("cron"); pub fn main() !void { const now = std.time.timestamp() * 1_000_000; // Parse a cron expression const schedule = try cron.Cron.parse("*/15 * * * *"); std.debug.print("expression: */15 * * * * (every 15 minutes)\n\n", .{}); // Get next 5 occurrences using nextN std.debug.print("next 5 occurrences (via nextN):\n", .{}); var buf: [5]i64 = undefined; const count = schedule.nextN(now, 5, &buf); for (buf[0..count]) |ts| { printDateTime(ts); } // Using the iterator pattern std.debug.print("\nusing iterator:\n", .{}); const weekdays = try cron.Cron.parse("0 9 * * 1-5"); // 9am weekdays var iter = weekdays.iter(now); var i: usize = 0; while (iter.next()) |ts| { printDateTime(ts); i += 1; if (i >= 3) break; } // Check if a time matches std.debug.print("\nmatches check:\n", .{}); const midnight = try cron.Cron.parse("0 0 * * *"); std.debug.print(" does midnight cron match now? {}\n", .{midnight.matches(now)}); } fn printDateTime(micros: i64) void { const dt = cron.DateTime.fromTimestamp(@divFloor(micros, 1_000_000)); std.debug.print(" {d}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2}:{d:0>2}\n", .{ dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, }); }