diff --git a/src/Duration.zig b/src/Duration.zig index 1627090..a513085 100644 --- a/src/Duration.zig +++ b/src/Duration.zig @@ -4,6 +4,31 @@ const temporal = @import("temporal.zig"); const Duration = @This(); +pub const RoundingOptions = temporal.RoundingOptions; +pub const ToStringOptions = temporal.ToStringRoundingOptions; +pub const ToStringRoundingOptions = temporal.ToStringRoundingOptions; +pub const Unit = temporal.Unit; +pub const RoundingMode = temporal.RoundingMode; +pub const Sign = temporal.Sign; +pub const PartialDuration = abi.c.PartialDuration; +/// Relative-to context for duration operations. +pub const RelativeTo = extern struct { + plain_date: ?*abi.c.PlainDate, + zoned_date_time: ?*abi.c.ZonedDateTime, + + fn toCApi(self: RelativeTo) abi.c.RelativeTo { + return .{ + .date = self.plain_date, + .zoned = self.zoned_date_time, + }; + } +}; +/// Options for Duration.total() providing unit and relative-to context. +pub const TotalOptions = struct { + unit: Unit, + relative_to: ?RelativeTo = null, +}; + _inner: *abi.c.Duration, /// Construct a Duration from years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds. @@ -216,30 +241,7 @@ fn wrapDuration(res: anytype) !Duration { return .{ ._inner = ptr }; } -// --- Public helper types ----------------------------------------------------- - -pub const PartialDuration = abi.c.PartialDuration; - -/// Relative-to context for duration operations. -pub const RelativeTo = extern struct { - plain_date: ?*abi.c.PlainDate, - zoned_date_time: ?*abi.c.ZonedDateTime, - - fn toCApi(self: RelativeTo) abi.c.RelativeTo { - return .{ - .date = self.plain_date, - .zoned = self.zoned_date_time, - }; - } -}; - -/// Options for Duration.total() providing unit and relative-to context. -pub const TotalOptions = struct { - unit: Unit, - relative_to: ?RelativeTo = null, -}; - -// --- Public type aliases and enums ------------------------------------------ +// --- Aliases and enums ------------------------------------------ const OptionU8 = abi.c.OptionU8; const OptionU32 = abi.c.OptionU32; @@ -249,13 +251,6 @@ const Precision = abi.c.Precision; const Unit_option = abi.c.Unit_option; const RoundingMode_option = abi.c.RoundingMode_option; -pub const RoundingOptions = temporal.RoundingOptions; -pub const ToStringOptions = temporal.ToStringRoundingOptions; -pub const ToStringRoundingOptions = temporal.ToStringRoundingOptions; -pub const Unit = temporal.Unit; -pub const RoundingMode = temporal.RoundingMode; -pub const Sign = temporal.Sign; - // --- Tests ------------------------------------------------------------------- test init { diff --git a/src/Instant.zig b/src/Instant.zig index b58b31e..d588802 100644 --- a/src/Instant.zig +++ b/src/Instant.zig @@ -3,17 +3,39 @@ const abi = @import("abi.zig"); const temporal = @import("temporal.zig"); const Duration = @import("Duration.zig"); -const Instant = @This(); -_inner: *abi.c.Instant, -epoch_milliseconds: i64, -epoch_nanoseconds: i128, +const Instant = @This(); pub const Unit = temporal.Unit; pub const RoundingMode = temporal.RoundingMode; pub const Sign = temporal.Sign; pub const RoundingOptions = temporal.RoundingOptions; pub const DifferenceSettings = temporal.DifferenceSettings; +/// Options for Instant.toString() +/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString +pub const ToStringOptions = struct { + /// Either an integer from 0 to 9, or null for "auto". + /// If null (auto), trailing zeros are removed from the fractional seconds. + /// Otherwise, the fractional part contains this many digits, padded with zeros or rounded as necessary. + fractional_second_digits: ?u8 = null, + + /// Specifies how to round off fractional second digits beyond fractionalSecondDigits. + /// Defaults to "trunc" (truncate). + rounding_mode: ?RoundingMode = null, + + /// Specifies the smallest unit to include in the output. + /// Possible values: "minute", "second", "millisecond", "microsecond", "nanosecond". + /// If specified, fractional_second_digits is ignored. + smallest_unit: ?Unit = null, + + /// Time zone to use. Either a time zone identifier string or null for UTC. + /// Note: In the Zig API, this must be pre-resolved to a TimeZone struct. + time_zone: ?abi.c.TimeZone = null, +}; + +_inner: *abi.c.Instant, +epoch_milliseconds: i64, +epoch_nanoseconds: i128, /// Construct from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds). pub fn init(epoch_ns: i128) !Instant { @@ -215,29 +237,7 @@ fn parseDuration(text: []const u8) !DurationHandle { return wrapDuration(abi.c.temporal_rs_Duration_from_utf8(view)); } -// --- Public helper types ----------------------------------------------------- - -/// Options for Instant.toString() -/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString -pub const ToStringOptions = struct { - /// Either an integer from 0 to 9, or null for "auto". - /// If null (auto), trailing zeros are removed from the fractional seconds. - /// Otherwise, the fractional part contains this many digits, padded with zeros or rounded as necessary. - fractional_second_digits: ?u8 = null, - - /// Specifies how to round off fractional second digits beyond fractionalSecondDigits. - /// Defaults to "trunc" (truncate). - rounding_mode: ?RoundingMode = null, - - /// Specifies the smallest unit to include in the output. - /// Possible values: "minute", "second", "millisecond", "microsecond", "nanosecond". - /// If specified, fractional_second_digits is ignored. - smallest_unit: ?Unit = null, - - /// Time zone to use. Either a time zone identifier string or null for UTC. - /// Note: In the Zig API, this must be pre-resolved to a TimeZone struct. - time_zone: ?abi.c.TimeZone = null, -}; +// --- Helper types ----------------------------------------------------- const DurationHandle = struct { ptr: *abi.c.Duration, diff --git a/src/Now.zig b/src/Now.zig index d3f40d8..1001e0b 100644 --- a/src/Now.zig +++ b/src/Now.zig @@ -1,10 +1,11 @@ -const Now = @This(); const Instant = @import("Instant.zig"); const PlainDate = @import("PlainDate.zig"); const PlainDateTime = @import("PlainDateTime.zig"); const PlainTime = @import("PlainTime.zig"); const ZonedDateTime = @import("ZonedDateTime.zig"); +const Now = @This(); + pub fn instant() error{Todo}!Instant { return error.Todo; } @@ -29,7 +30,7 @@ pub fn zonedDateTimeISO() error{Todo}!ZonedDateTime { return error.Todo; } -// --- Tests --------------------- +// ---------- Tests --------------------- test instant { if (true) return error.Todo; } diff --git a/src/PlainDate.zig b/src/PlainDate.zig index 7fb3937..2430328 100644 --- a/src/PlainDate.zig +++ b/src/PlainDate.zig @@ -1,27 +1,29 @@ const std = @import("std"); -const PlainDate = @This(); + const PlainDateTime = @import("PlainDateTime.zig"); const PlainMonthDay = @import("PlainMonthDay.zig"); const PlainYearMonth = @import("PlainYearMonth.zig"); const ZonedDateTime = @import("ZonedDateTime.zig"); const Duration = @import("Duration.zig"); -pub var calendarId: []const u8 = ""; -pub var day: i64 = 0; -pub var dayOfWeek: i64 = 0; -pub var dayOfYear: i64 = 0; -pub var daysInMonth: i64 = 0; -pub var daysInWeek: i64 = 0; -pub var daysInYear: i64 = 0; -pub var era: []const u8 = ""; -pub var eraYear: i64 = 0; -pub var inLeapYear: bool = false; -pub var month: i64 = 0; -pub var monthCode: []const u8 = ""; -pub var monthsInYear: i64 = 0; -pub var weekOfYear: i64 = 0; -pub var year: i64 = 0; -pub var yearOfWeek: i64 = 0; +const PlainDate = @This(); + +calendar_id: []const u8, +day: i64 = 0, +day_of_week: i64, +day_of_year: i64, +days_in_month: i64, +days_in_week: i64, +days_in_year: i64, +era: []const u8, +era_year: i64, +in_leap_year: bool, +month: i64, +month_code: []const u8, +months_in_year: i64, +week_of_year: i64, +year: i64, +year_of_week: i64, pub fn init() error{Todo}!PlainDate { return error.Todo; @@ -95,6 +97,7 @@ pub fn withCalendar() error{Todo}!PlainDate { return error.Todo; } +// ---------- Tests --------------------- test compare { if (true) return error.Todo; } diff --git a/src/PlainDateTime.zig b/src/PlainDateTime.zig index 8379e33..cca9f27 100644 --- a/src/PlainDateTime.zig +++ b/src/PlainDateTime.zig @@ -1,32 +1,34 @@ const std = @import("std"); -const PlainDateTime = @This(); + const PlainDate = @import("PlainDate.zig"); const PlainTime = @import("PlainTime.zig"); const ZonedDateTime = @import("ZonedDateTime.zig"); const Duration = @import("Duration.zig"); -pub var calendarId: []const u8 = ""; -pub var day: i64 = 0; -pub var dayOfWeek: i64 = 0; -pub var dayOfYear: i64 = 0; -pub var daysInMonth: i64 = 0; -pub var daysInWeek: i64 = 0; -pub var daysInYear: i64 = 0; -pub var era: []const u8 = ""; -pub var eraYear: i64 = 0; -pub var hour: i64 = 0; -pub var inLeapYear: bool = false; -pub var microsecond: i64 = 0; -pub var millisecond: i64 = 0; -pub var minute: i64 = 0; -pub var month: i64 = 0; -pub var monthCode: []const u8 = ""; -pub var monthsInYear: i64 = 0; -pub var nanosecond: i64 = 0; -pub var second: i64 = 0; -pub var weekOfYear: i64 = 0; -pub var year: i64 = 0; -pub var yearOfWeek: i64 = 0; +const PlainDateTime = @This(); + +calendar_id: []const u8, +day: i64, +day_of_week: i64, +day_of_year: i64, +days_in_month: i64, +days_in_week: i64, +days_in_year: i64, +era: []const u8, +era_year: i64, +hour: i64, +in_leap_year: bool, +microsecond: i64, +millisecond: i64, +minute: i64, +month: i64, +month_code: []const u8, +months_in_year: i64, +nanosecond: i64, +second: i64, +week_of_year: i64, +year: i64, +year_of_week: i64, pub fn init() error{Todo}!PlainDateTime { return error.Todo; @@ -104,6 +106,7 @@ pub fn withPlainTime() error{Todo}!PlainDateTime { return error.Todo; } +// ---------- Tests --------------------- test compare { if (true) return error.Todo; } diff --git a/src/PlainMonthDay.zig b/src/PlainMonthDay.zig index f9fce12..daf95ca 100644 --- a/src/PlainMonthDay.zig +++ b/src/PlainMonthDay.zig @@ -2,9 +2,9 @@ const std = @import("std"); const PlainMonthDay = @This(); const PlainDate = @import("PlainDate.zig"); -pub var calendarId: []const u8 = ""; -pub var day: i64 = 0; -pub var monthCode: []const u8 = ""; +calendar_id: []const u8, +day: i64, +month_code: []const u8, pub fn init() error{Todo}!PlainMonthDay { return error.Todo; @@ -42,6 +42,7 @@ pub fn with() error{Todo}!PlainMonthDay { return error.Todo; } +// ---------- Tests --------------------- test from { if (true) return error.Todo; } diff --git a/src/PlainTime.zig b/src/PlainTime.zig index 37f4596..caa4468 100644 --- a/src/PlainTime.zig +++ b/src/PlainTime.zig @@ -2,12 +2,12 @@ const std = @import("std"); const PlainTime = @This(); const Duration = @import("Duration.zig"); -pub var hour: i64 = 0; -pub var microsecond: i64 = 0; -pub var millisecond: i64 = 0; -pub var minute: i64 = 0; -pub var nanosecond: i64 = 0; -pub var second: i64 = 0; +hour: i64, +microsecond: i64, +millisecond: i64, +minute: i64, +nanosecond: i64, +second: i64, pub fn init() error{Todo}!PlainTime { return error.Todo; @@ -65,6 +65,7 @@ pub fn with() error{Todo}!PlainTime { return error.Todo; } +// ---------- Tests --------------------- test compare { if (true) return error.Todo; } diff --git a/src/PlainYearMonth.zig b/src/PlainYearMonth.zig index f636228..1cff0af 100644 --- a/src/PlainYearMonth.zig +++ b/src/PlainYearMonth.zig @@ -3,16 +3,16 @@ const PlainYearMonth = @This(); const PlainDate = @import("PlainDate.zig"); const Duration = @import("Duration.zig"); -pub var calendarId: []const u8 = ""; -pub var daysInMonth: i64 = 0; -pub var daysInYear: i64 = 0; -pub var era: []const u8 = ""; -pub var eraYear: i64 = 0; -pub var inLeapYear: bool = false; -pub var month: i64 = 0; -pub var monthCode: []const u8 = ""; -pub var monthsInYear: i64 = 0; -pub var year: i64 = 0; +calendar_id: []const u8, +days_in_month: i64, +days_in_year: i64, +era: []const u8, +era_year: i64, +in_leap_year: bool, +month: i64, +month_code: []const u8, +months_in_year: i64, +year: i64, pub fn init() error{Todo}!PlainYearMonth { return error.Todo; @@ -70,6 +70,7 @@ pub fn with() error{Todo}!PlainYearMonth { return error.Todo; } +// ---------- Tests --------------------- test compare { if (true) return error.Todo; } diff --git a/src/ZonedDateTime.zig b/src/ZonedDateTime.zig index 96d3e3a..4efda94 100644 --- a/src/ZonedDateTime.zig +++ b/src/ZonedDateTime.zig @@ -1,39 +1,41 @@ const std = @import("std"); -const ZonedDateTime = @This(); + const Instant = @import("Instant.zig"); const PlainDate = @import("PlainDate.zig"); const PlainDateTime = @import("PlainDateTime.zig"); const PlainTime = @import("PlainTime.zig"); const Duration = @import("Duration.zig"); -pub var calendarId: []const u8 = ""; -pub var day: i64 = 0; -pub var dayOfWeek: i64 = 0; -pub var dayOfYear: i64 = 0; -pub var daysInMonth: i64 = 0; -pub var daysInWeek: i64 = 0; -pub var daysInYear: i64 = 0; -pub var epochMilliseconds: i64 = 0; -pub var epochNanoseconds: i128 = 0; -pub var era: []const u8 = ""; -pub var eraYear: i64 = 0; -pub var hour: i64 = 0; -pub var hoursInDay: i64 = 0; -pub var inLeapYear: bool = false; -pub var microsecond: i64 = 0; -pub var millisecond: i64 = 0; -pub var minute: i64 = 0; -pub var month: i64 = 0; -pub var monthCode: []const u8 = ""; -pub var monthsInYear: i64 = 0; -pub var nanosecond: i64 = 0; -pub var offset: []const u8 = ""; -pub var offsetNanoseconds: i64 = 0; -pub var second: i64 = 0; -pub var timeZoneId: []const u8 = ""; -pub var weekOfYear: i64 = 0; -pub var year: i64 = 0; -pub var yearOfWeek: i64 = 0; +const ZonedDateTime = @This(); + +calendar_id: []const u8, +day: i64, +day_of_week: i64, +day_of_year: i64, +days_in_month: i64, +days_in_week: i64, +days_in_year: i64, +epoch_milliseconds: i64, +epoch_nanoseconds: i128, +era: []const u8, +era_year: i64, +hour: i64, +hours_in_day: i64, +in_leap_year: bool, +microsecond: i64, +millisecond: i64, +minute: i64, +month: i64, +month_code: []const u8, +months_in_year: i64, +nanosecond: i64, +offset: []const u8, +offset_nanoseconds: i64, +second: i64, +time_zone_id: []const u8, +week_of_year: i64, +year: i64, +year_of_week: i64, pub fn init() error{Todo}!ZonedDateTime { return error.Todo; @@ -127,6 +129,7 @@ pub fn withTimeZone() error{Todo}!ZonedDateTime { return error.Todo; } +// ---------- Tests --------------------- test compare { if (true) return error.Todo; } diff --git a/src/root.zig b/src/root.zig index 6293f27..44b503a 100644 --- a/src/root.zig +++ b/src/root.zig @@ -12,6 +12,7 @@ const Temporal = @This(); test Temporal { const std = @import("std"); + _ = @import("abi.zig"); const expected_scopes = .{ "Duration",