chore: properly organize code

This commit is contained in:
Nurul Huda (Apon) 2026-01-26 15:44:43 +06:00
parent d804953db0
commit 6a8a52640f
No known key found for this signature in database
GPG key ID: 5D3F1DE2855A2F79
10 changed files with 157 additions and 148 deletions

View file

@ -4,6 +4,31 @@ const temporal = @import("temporal.zig");
const Duration = @This(); 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, _inner: *abi.c.Duration,
/// Construct a Duration from years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds. /// 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 }; return .{ ._inner = ptr };
} }
// --- Public helper types ----------------------------------------------------- // --- Aliases and enums ------------------------------------------
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 ------------------------------------------
const OptionU8 = abi.c.OptionU8; const OptionU8 = abi.c.OptionU8;
const OptionU32 = abi.c.OptionU32; const OptionU32 = abi.c.OptionU32;
@ -249,13 +251,6 @@ const Precision = abi.c.Precision;
const Unit_option = abi.c.Unit_option; const Unit_option = abi.c.Unit_option;
const RoundingMode_option = abi.c.RoundingMode_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 ------------------------------------------------------------------- // --- Tests -------------------------------------------------------------------
test init { test init {

View file

@ -3,17 +3,39 @@ const abi = @import("abi.zig");
const temporal = @import("temporal.zig"); const temporal = @import("temporal.zig");
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
const Instant = @This();
_inner: *abi.c.Instant, const Instant = @This();
epoch_milliseconds: i64,
epoch_nanoseconds: i128,
pub const Unit = temporal.Unit; pub const Unit = temporal.Unit;
pub const RoundingMode = temporal.RoundingMode; pub const RoundingMode = temporal.RoundingMode;
pub const Sign = temporal.Sign; pub const Sign = temporal.Sign;
pub const RoundingOptions = temporal.RoundingOptions; pub const RoundingOptions = temporal.RoundingOptions;
pub const DifferenceSettings = temporal.DifferenceSettings; 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). /// Construct from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds).
pub fn init(epoch_ns: i128) !Instant { 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)); return wrapDuration(abi.c.temporal_rs_Duration_from_utf8(view));
} }
// --- Public helper types ----------------------------------------------------- // --- 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,
};
const DurationHandle = struct { const DurationHandle = struct {
ptr: *abi.c.Duration, ptr: *abi.c.Duration,

View file

@ -1,10 +1,11 @@
const Now = @This();
const Instant = @import("Instant.zig"); const Instant = @import("Instant.zig");
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
const PlainDateTime = @import("PlainDateTime.zig"); const PlainDateTime = @import("PlainDateTime.zig");
const PlainTime = @import("PlainTime.zig"); const PlainTime = @import("PlainTime.zig");
const ZonedDateTime = @import("ZonedDateTime.zig"); const ZonedDateTime = @import("ZonedDateTime.zig");
const Now = @This();
pub fn instant() error{Todo}!Instant { pub fn instant() error{Todo}!Instant {
return error.Todo; return error.Todo;
} }
@ -29,7 +30,7 @@ pub fn zonedDateTimeISO() error{Todo}!ZonedDateTime {
return error.Todo; return error.Todo;
} }
// --- Tests --------------------- // ---------- Tests ---------------------
test instant { test instant {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -1,27 +1,29 @@
const std = @import("std"); const std = @import("std");
const PlainDate = @This();
const PlainDateTime = @import("PlainDateTime.zig"); const PlainDateTime = @import("PlainDateTime.zig");
const PlainMonthDay = @import("PlainMonthDay.zig"); const PlainMonthDay = @import("PlainMonthDay.zig");
const PlainYearMonth = @import("PlainYearMonth.zig"); const PlainYearMonth = @import("PlainYearMonth.zig");
const ZonedDateTime = @import("ZonedDateTime.zig"); const ZonedDateTime = @import("ZonedDateTime.zig");
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
pub var calendarId: []const u8 = ""; const PlainDate = @This();
pub var day: i64 = 0;
pub var dayOfWeek: i64 = 0; calendar_id: []const u8,
pub var dayOfYear: i64 = 0; day: i64 = 0,
pub var daysInMonth: i64 = 0; day_of_week: i64,
pub var daysInWeek: i64 = 0; day_of_year: i64,
pub var daysInYear: i64 = 0; days_in_month: i64,
pub var era: []const u8 = ""; days_in_week: i64,
pub var eraYear: i64 = 0; days_in_year: i64,
pub var inLeapYear: bool = false; era: []const u8,
pub var month: i64 = 0; era_year: i64,
pub var monthCode: []const u8 = ""; in_leap_year: bool,
pub var monthsInYear: i64 = 0; month: i64,
pub var weekOfYear: i64 = 0; month_code: []const u8,
pub var year: i64 = 0; months_in_year: i64,
pub var yearOfWeek: i64 = 0; week_of_year: i64,
year: i64,
year_of_week: i64,
pub fn init() error{Todo}!PlainDate { pub fn init() error{Todo}!PlainDate {
return error.Todo; return error.Todo;
@ -95,6 +97,7 @@ pub fn withCalendar() error{Todo}!PlainDate {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test compare { test compare {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -1,32 +1,34 @@
const std = @import("std"); const std = @import("std");
const PlainDateTime = @This();
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
const PlainTime = @import("PlainTime.zig"); const PlainTime = @import("PlainTime.zig");
const ZonedDateTime = @import("ZonedDateTime.zig"); const ZonedDateTime = @import("ZonedDateTime.zig");
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
pub var calendarId: []const u8 = ""; const PlainDateTime = @This();
pub var day: i64 = 0;
pub var dayOfWeek: i64 = 0; calendar_id: []const u8,
pub var dayOfYear: i64 = 0; day: i64,
pub var daysInMonth: i64 = 0; day_of_week: i64,
pub var daysInWeek: i64 = 0; day_of_year: i64,
pub var daysInYear: i64 = 0; days_in_month: i64,
pub var era: []const u8 = ""; days_in_week: i64,
pub var eraYear: i64 = 0; days_in_year: i64,
pub var hour: i64 = 0; era: []const u8,
pub var inLeapYear: bool = false; era_year: i64,
pub var microsecond: i64 = 0; hour: i64,
pub var millisecond: i64 = 0; in_leap_year: bool,
pub var minute: i64 = 0; microsecond: i64,
pub var month: i64 = 0; millisecond: i64,
pub var monthCode: []const u8 = ""; minute: i64,
pub var monthsInYear: i64 = 0; month: i64,
pub var nanosecond: i64 = 0; month_code: []const u8,
pub var second: i64 = 0; months_in_year: i64,
pub var weekOfYear: i64 = 0; nanosecond: i64,
pub var year: i64 = 0; second: i64,
pub var yearOfWeek: i64 = 0; week_of_year: i64,
year: i64,
year_of_week: i64,
pub fn init() error{Todo}!PlainDateTime { pub fn init() error{Todo}!PlainDateTime {
return error.Todo; return error.Todo;
@ -104,6 +106,7 @@ pub fn withPlainTime() error{Todo}!PlainDateTime {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test compare { test compare {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -2,9 +2,9 @@ const std = @import("std");
const PlainMonthDay = @This(); const PlainMonthDay = @This();
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
pub var calendarId: []const u8 = ""; calendar_id: []const u8,
pub var day: i64 = 0; day: i64,
pub var monthCode: []const u8 = ""; month_code: []const u8,
pub fn init() error{Todo}!PlainMonthDay { pub fn init() error{Todo}!PlainMonthDay {
return error.Todo; return error.Todo;
@ -42,6 +42,7 @@ pub fn with() error{Todo}!PlainMonthDay {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test from { test from {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -2,12 +2,12 @@ const std = @import("std");
const PlainTime = @This(); const PlainTime = @This();
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
pub var hour: i64 = 0; hour: i64,
pub var microsecond: i64 = 0; microsecond: i64,
pub var millisecond: i64 = 0; millisecond: i64,
pub var minute: i64 = 0; minute: i64,
pub var nanosecond: i64 = 0; nanosecond: i64,
pub var second: i64 = 0; second: i64,
pub fn init() error{Todo}!PlainTime { pub fn init() error{Todo}!PlainTime {
return error.Todo; return error.Todo;
@ -65,6 +65,7 @@ pub fn with() error{Todo}!PlainTime {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test compare { test compare {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -3,16 +3,16 @@ const PlainYearMonth = @This();
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
pub var calendarId: []const u8 = ""; calendar_id: []const u8,
pub var daysInMonth: i64 = 0; days_in_month: i64,
pub var daysInYear: i64 = 0; days_in_year: i64,
pub var era: []const u8 = ""; era: []const u8,
pub var eraYear: i64 = 0; era_year: i64,
pub var inLeapYear: bool = false; in_leap_year: bool,
pub var month: i64 = 0; month: i64,
pub var monthCode: []const u8 = ""; month_code: []const u8,
pub var monthsInYear: i64 = 0; months_in_year: i64,
pub var year: i64 = 0; year: i64,
pub fn init() error{Todo}!PlainYearMonth { pub fn init() error{Todo}!PlainYearMonth {
return error.Todo; return error.Todo;
@ -70,6 +70,7 @@ pub fn with() error{Todo}!PlainYearMonth {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test compare { test compare {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -1,39 +1,41 @@
const std = @import("std"); const std = @import("std");
const ZonedDateTime = @This();
const Instant = @import("Instant.zig"); const Instant = @import("Instant.zig");
const PlainDate = @import("PlainDate.zig"); const PlainDate = @import("PlainDate.zig");
const PlainDateTime = @import("PlainDateTime.zig"); const PlainDateTime = @import("PlainDateTime.zig");
const PlainTime = @import("PlainTime.zig"); const PlainTime = @import("PlainTime.zig");
const Duration = @import("Duration.zig"); const Duration = @import("Duration.zig");
pub var calendarId: []const u8 = ""; const ZonedDateTime = @This();
pub var day: i64 = 0;
pub var dayOfWeek: i64 = 0; calendar_id: []const u8,
pub var dayOfYear: i64 = 0; day: i64,
pub var daysInMonth: i64 = 0; day_of_week: i64,
pub var daysInWeek: i64 = 0; day_of_year: i64,
pub var daysInYear: i64 = 0; days_in_month: i64,
pub var epochMilliseconds: i64 = 0; days_in_week: i64,
pub var epochNanoseconds: i128 = 0; days_in_year: i64,
pub var era: []const u8 = ""; epoch_milliseconds: i64,
pub var eraYear: i64 = 0; epoch_nanoseconds: i128,
pub var hour: i64 = 0; era: []const u8,
pub var hoursInDay: i64 = 0; era_year: i64,
pub var inLeapYear: bool = false; hour: i64,
pub var microsecond: i64 = 0; hours_in_day: i64,
pub var millisecond: i64 = 0; in_leap_year: bool,
pub var minute: i64 = 0; microsecond: i64,
pub var month: i64 = 0; millisecond: i64,
pub var monthCode: []const u8 = ""; minute: i64,
pub var monthsInYear: i64 = 0; month: i64,
pub var nanosecond: i64 = 0; month_code: []const u8,
pub var offset: []const u8 = ""; months_in_year: i64,
pub var offsetNanoseconds: i64 = 0; nanosecond: i64,
pub var second: i64 = 0; offset: []const u8,
pub var timeZoneId: []const u8 = ""; offset_nanoseconds: i64,
pub var weekOfYear: i64 = 0; second: i64,
pub var year: i64 = 0; time_zone_id: []const u8,
pub var yearOfWeek: i64 = 0; week_of_year: i64,
year: i64,
year_of_week: i64,
pub fn init() error{Todo}!ZonedDateTime { pub fn init() error{Todo}!ZonedDateTime {
return error.Todo; return error.Todo;
@ -127,6 +129,7 @@ pub fn withTimeZone() error{Todo}!ZonedDateTime {
return error.Todo; return error.Todo;
} }
// ---------- Tests ---------------------
test compare { test compare {
if (true) return error.Todo; if (true) return error.Todo;
} }

View file

@ -12,6 +12,7 @@ const Temporal = @This();
test Temporal { test Temporal {
const std = @import("std"); const std = @import("std");
_ = @import("abi.zig");
const expected_scopes = .{ const expected_scopes = .{
"Duration", "Duration",