Changes
3 changed files (+128/-6)
-
-
@@ -230,7 +230,7 @@ };latitude: ?f64 = null, longitude: ?f64 = null, offset_hour: f64 = 0, offset_mins: i32 = 0, twilight_angle: ?TwilightAngle = null, utc: bool = false, debug: bool = false,
-
@@ -246,6 +246,7 @@ InvalidMonth,InvalidYearSince2000, InvalidEventType, InvalidAngle, InvalidOffset, }; pub const ReportOptions = struct {
-
@@ -554,6 +555,68 @@ self.longitude = lon;return; } // Hyphen-less one is for compatibility. // TODO: Delete the hyphen-less one once migration is completed. if (std.mem.eql(u8, "-o", arg) or std.mem.eql(u8, "--offset", arg) or std.mem.eql(u8, "offset", arg)) { const next = args.next() orelse { std.log.err("{s} option requires a value", .{arg}); return ParseArgsError.MissingValue; }; const i: u1, const modifier: i2 = sign: { break :sign if (std.mem.startsWith(u8, next, "-")) .{ 1, -1, } else .{ 0, 1, }; }; if (std.mem.indexOfScalarPos(u8, next, i, ':')) |colon_pos| { // HH:MM const hrs = std.fmt.parseUnsigned(u7, next[i..colon_pos], 10) catch { std.log.err("Hour part of {s} option must be valid integer between 0 and 99", .{arg}); return ParseArgsError.InvalidOffset; }; if (hrs > 99) { std.log.err("Hour part of {s} option must be between 0 and 99", .{arg}); return ParseArgsError.InvalidOffset; } if (next[i..].len == colon_pos + 1) { std.log.err("Value of {s} option cannot end with colon", .{arg}); return ParseArgsError.InvalidOffset; } const mins = std.fmt.parseUnsigned(u6, next[colon_pos + 1 ..], 10) catch { std.log.err("Minute part of {s} option must be valid integer between 0 and 59", .{arg}); return ParseArgsError.InvalidOffset; }; if (mins > 59) { std.log.err("Minute part of {s} option must be between 0 and 59", .{arg}); return ParseArgsError.InvalidOffset; } self.offset_mins = @as(i32, (@as(i32, hrs) * 60) + mins) * modifier; return; } else { // MM const parsed = std.fmt.parseUnsigned(u7, next[i..], 10) catch { std.log.err("Value of {s} option must be valid integer between -99 and 99", .{arg}); return ParseArgsError.InvalidOffset; }; if (parsed > 99) { std.log.err("Value of {s} option must be between -99 and 99", .{arg}); return ParseArgsError.InvalidOffset; } self.offset_mins = @as(i32, parsed) * modifier; return; } } return ParseArgsError.UnknownArg; }
-
@@ -673,7 +736,7 @@return c.runStruct{ .latitude = self.latitude orelse c.DEFAULT_LATITUDE, .longitude = self.longitude orelse c.DEFAULT_LONGITUDE, .offsetHour = self.offset_hour, .offsetHour = @as(f64, @floatFromInt(self.offset_mins)) / 60.0, .twilightAngle = twilight_angle.toFloat(), .nowTimet = now, .targetTimet = target_time,
-
-
-
@@ -69,6 +69,10 @@ \\ * daylight\\ * civil \\ * nautical \\ * astronomical \\-o <DURATION>, --offset <DURATION> \\ Time offset for sunrise and sunset time, towards noon. \\ <DURATION> must be "MM" (minutes) or "HH:MM", and either \\ can be negative. \\ \\[Commands] \\poll Prints whether it's DAY or NIGHT.
-
@@ -84,10 +88,6 @@ \\ * sunset\\ When this option is not set, sunwait targets both. \\ You can specify this option multiple times to explicitly \\ tell sunwait to target both. \\ \\[Common Parameters] \\OFFSET Time offset for sunrise and sunset time, towards noon. \\ Format must be "MM" (minutes) or "HH:MM". \\ \\See man page for "sunwait(1)" for more. \\
-
-
-
@@ -29,6 +29,7 @@ tz: []const u8 = "UTC",event: ?enum { sunset, sunrise } = null, twilight: ?[]const u8 = null, twilight_angle: ?[]const u8 = null, offset: ?[]const u8 = null, }; fn list(allocator: std.mem.Allocator, opts: ListOptions) !std.process.Child.RunResult {
-
@@ -44,6 +45,12 @@ try args.append(opts.bin);if (opts.utc) { try args.append("utc"); } if (opts.offset) |offset| { try args.append("offset"); try args.append(offset); } try args.append("list"); if (opts.days) |days| { try args.append(days);
-
@@ -246,3 +253,55 @@ try std.testing.expectEqual(legacy.term.Exited, new.term.Exited);try std.testing.expectEqualStrings(legacy.stderr, new.stderr); try std.testing.expectEqualStrings(legacy.stdout, new.stdout); } test "Should behave same with an offset" { const legacy = try list(std.testing.allocator, .{ .bin = config.legacy_bin, .tz = "Europe/Paris", .utc = true, .event = .sunset, .offset = "00:30", }); defer std.testing.allocator.free(legacy.stderr); defer std.testing.allocator.free(legacy.stdout); const new = try list(std.testing.allocator, .{ .bin = config.new_bin, .tz = "Europe/Paris", .utc = true, .event = .sunset, .offset = "00:30", }); defer std.testing.allocator.free(new.stderr); defer std.testing.allocator.free(new.stdout); try std.testing.expectEqual(legacy.term.Exited, new.term.Exited); try std.testing.expectEqualStrings(legacy.stderr, new.stderr); try std.testing.expectEqualStrings(legacy.stdout, new.stdout); } test "Should behave same with a negative offset" { const legacy = try list(std.testing.allocator, .{ .bin = config.legacy_bin, .tz = "Europe/Paris", .utc = true, .event = .sunset, .offset = "-11:00", }); defer std.testing.allocator.free(legacy.stderr); defer std.testing.allocator.free(legacy.stdout); const new = try list(std.testing.allocator, .{ .bin = config.new_bin, .tz = "Europe/Paris", .utc = true, .event = .sunset, .offset = "-11:00", }); defer std.testing.allocator.free(new.stderr); defer std.testing.allocator.free(new.stdout); try std.testing.expectEqual(legacy.term.Exited, new.term.Exited); try std.testing.expectEqualStrings(legacy.stderr, new.stderr); try std.testing.expectEqualStrings(legacy.stdout, new.stdout); }
-