ci: add docs deploy to gh pages
This commit is contained in:
parent
b03d42e72d
commit
6b27752cfe
6 changed files with 143 additions and 57 deletions
51
.github/workflows/docs.yml
vendored
Normal file
51
.github/workflows/docs.yml
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
name: Docs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: 'pages'
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Zig
|
||||||
|
uses: mlugg/setup-zig@v2
|
||||||
|
with:
|
||||||
|
version: 0.16.0
|
||||||
|
|
||||||
|
- name: Setup Pages
|
||||||
|
uses: actions/configure-pages@v5
|
||||||
|
|
||||||
|
- name: Build Docs
|
||||||
|
run: zig build docs
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-pages-artifact@v3
|
||||||
|
with:
|
||||||
|
path: ./zig-out/docs
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
environment:
|
||||||
|
name: github-pages
|
||||||
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Deploy to GitHub Pages
|
||||||
|
id: deployment
|
||||||
|
uses: actions/deploy-pages@v4
|
||||||
|
|
@ -8,7 +8,8 @@ const ZonedDateTime = @import("ZonedDateTime.zig");
|
||||||
|
|
||||||
/// The `Temporal.Duration` object represents a difference between two time points, which can be used in date/time arithmetic.
|
/// The `Temporal.Duration` object represents a difference between two time points, which can be used in date/time arithmetic.
|
||||||
/// It is fundamentally represented as a combination of years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds values.
|
/// It is fundamentally represented as a combination of years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds values.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration
|
///
|
||||||
|
/// See: [Temporal.Duration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration)
|
||||||
const Duration = @This();
|
const Duration = @This();
|
||||||
|
|
||||||
_inner: *abi.c.Duration,
|
_inner: *abi.c.Duration,
|
||||||
|
|
@ -40,7 +41,8 @@ pub const RoundingOptions = struct {
|
||||||
|
|
||||||
/// Partial duration specification for creating Duration objects.
|
/// Partial duration specification for creating Duration objects.
|
||||||
/// This is a wrapper around the C API type to avoid exposing C types directly.
|
/// This is a wrapper around the C API type to avoid exposing C types directly.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/from
|
///
|
||||||
|
/// See: [Temporal.Duration.from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/from)
|
||||||
pub const PartialDuration = struct {
|
pub const PartialDuration = struct {
|
||||||
years: ?i64 = null,
|
years: ?i64 = null,
|
||||||
months: ?i64 = null,
|
months: ?i64 = null,
|
||||||
|
|
@ -55,7 +57,8 @@ pub const PartialDuration = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Relative-to context for duration operations, used for balancing and calendar-aware math.
|
/// Relative-to context for duration operations, used for balancing and calendar-aware math.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations
|
///
|
||||||
|
/// See: [Temporal.Duration#calendar_durations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration#calendar_durations)
|
||||||
pub const RelativeTo = union(enum) {
|
pub const RelativeTo = union(enum) {
|
||||||
plain_date: PlainDate,
|
plain_date: PlainDate,
|
||||||
plain_date_time: PlainDateTime,
|
plain_date_time: PlainDateTime,
|
||||||
|
|
@ -78,7 +81,8 @@ pub const CompareOptions = struct {
|
||||||
|
|
||||||
/// 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.
|
||||||
/// Equivalent to `Temporal.Duration()` constructor.
|
/// Equivalent to `Temporal.Duration()` constructor.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/Duration
|
///
|
||||||
|
/// See: [Temporal.Duration.Duration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/Duration)
|
||||||
pub fn init(
|
pub fn init(
|
||||||
years_val: i64,
|
years_val: i64,
|
||||||
months_val: i64,
|
months_val: i64,
|
||||||
|
|
@ -164,105 +168,122 @@ fn isTimeWithinRange(self: Duration) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of years in the duration.
|
/// Returns the number of years in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/years
|
///
|
||||||
|
/// See: [Temporal.Duration.years](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/years)
|
||||||
pub fn years(self: Duration) i64 {
|
pub fn years(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_years(self._inner);
|
return abi.c.temporal_rs_Duration_years(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of months in the duration.
|
/// Returns the number of months in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/months
|
///
|
||||||
|
/// See: [Temporal.Duration.months](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/months)
|
||||||
pub fn months(self: Duration) i64 {
|
pub fn months(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_months(self._inner);
|
return abi.c.temporal_rs_Duration_months(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of weeks in the duration.
|
/// Returns the number of weeks in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/weeks
|
///
|
||||||
|
/// See: [Temporal.Duration.weeks](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/weeks)
|
||||||
pub fn weeks(self: Duration) i64 {
|
pub fn weeks(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_weeks(self._inner);
|
return abi.c.temporal_rs_Duration_weeks(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of days in the duration.
|
/// Returns the number of days in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/days
|
///
|
||||||
|
/// See: [Temporal.Duration.days](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/days)
|
||||||
pub fn days(self: Duration) i64 {
|
pub fn days(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_days(self._inner);
|
return abi.c.temporal_rs_Duration_days(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of hours in the duration.
|
/// Returns the number of hours in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/hours
|
///
|
||||||
|
/// See: [Temporal.Duration.hours](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/hours)
|
||||||
pub fn hours(self: Duration) i64 {
|
pub fn hours(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_hours(self._inner);
|
return abi.c.temporal_rs_Duration_hours(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of minutes in the duration.
|
/// Returns the number of minutes in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/minutes
|
///
|
||||||
|
/// See: [Temporal.Duration.minutes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/minutes)
|
||||||
pub fn minutes(self: Duration) i64 {
|
pub fn minutes(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_minutes(self._inner);
|
return abi.c.temporal_rs_Duration_minutes(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of seconds in the duration.
|
/// Returns the number of seconds in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/seconds
|
///
|
||||||
|
/// See: [Temporal.Duration.seconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/seconds)
|
||||||
pub fn seconds(self: Duration) i64 {
|
pub fn seconds(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_seconds(self._inner);
|
return abi.c.temporal_rs_Duration_seconds(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of milliseconds in the duration.
|
/// Returns the number of milliseconds in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/milliseconds
|
///
|
||||||
|
/// See: [Temporal.Duration.milliseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/milliseconds)
|
||||||
pub fn milliseconds(self: Duration) i64 {
|
pub fn milliseconds(self: Duration) i64 {
|
||||||
return abi.c.temporal_rs_Duration_milliseconds(self._inner);
|
return abi.c.temporal_rs_Duration_milliseconds(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of microseconds in the duration.
|
/// Returns the number of microseconds in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/microseconds
|
///
|
||||||
|
/// See: [Temporal.Duration.microseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/microseconds)
|
||||||
pub fn microseconds(self: Duration) f64 {
|
pub fn microseconds(self: Duration) f64 {
|
||||||
return abi.c.temporal_rs_Duration_microseconds(self._inner);
|
return abi.c.temporal_rs_Duration_microseconds(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of nanoseconds in the duration.
|
/// Returns the number of nanoseconds in the duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/nanoseconds
|
///
|
||||||
|
/// See: [Temporal.Duration.nanoseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/nanoseconds)
|
||||||
pub fn nanoseconds(self: Duration) f64 {
|
pub fn nanoseconds(self: Duration) f64 {
|
||||||
return abi.c.temporal_rs_Duration_nanoseconds(self._inner);
|
return abi.c.temporal_rs_Duration_nanoseconds(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the sign of the duration: positive (1), zero (0), or negative (-1).
|
/// Returns the sign of the duration: positive (1), zero (0), or negative (-1).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/sign
|
///
|
||||||
|
/// See: [Temporal.Duration.sign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/sign)
|
||||||
pub fn sign(self: Duration) Sign {
|
pub fn sign(self: Duration) Sign {
|
||||||
return abi.from.sign(abi.c.temporal_rs_Duration_sign(self._inner));
|
return abi.from.sign(abi.c.temporal_rs_Duration_sign(self._inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the duration is zero (all fields are zero), false otherwise.
|
/// Returns true if the duration is zero (all fields are zero), false otherwise.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/blank
|
///
|
||||||
|
/// See: [Temporal.Duration.blank](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/blank)
|
||||||
pub fn blank(self: Duration) bool {
|
pub fn blank(self: Duration) bool {
|
||||||
return abi.c.temporal_rs_Duration_is_zero(self._inner);
|
return abi.c.temporal_rs_Duration_is_zero(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Duration with the absolute value (all components positive).
|
/// Returns a new Duration with the absolute value (all components positive).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/abs
|
///
|
||||||
|
/// See: [Temporal.Duration.abs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/abs)
|
||||||
pub fn abs(self: Duration) Duration {
|
pub fn abs(self: Duration) Duration {
|
||||||
const ptr: *abi.c.Duration = abi.c.temporal_rs_Duration_abs(self._inner) orelse unreachable;
|
const ptr: *abi.c.Duration = abi.c.temporal_rs_Duration_abs(self._inner) orelse unreachable;
|
||||||
return .{ ._inner = ptr };
|
return .{ ._inner = ptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Duration with all components negated (sign reversed).
|
/// Returns a new Duration with all components negated (sign reversed).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated
|
///
|
||||||
|
/// See: [Temporal.Duration.negated](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/negated)
|
||||||
pub fn negated(self: Duration) Duration {
|
pub fn negated(self: Duration) Duration {
|
||||||
const ptr: *abi.c.Duration = abi.c.temporal_rs_Duration_negated(self._inner) orelse unreachable;
|
const ptr: *abi.c.Duration = abi.c.temporal_rs_Duration_negated(self._inner) orelse unreachable;
|
||||||
return .{ ._inner = ptr };
|
return .{ ._inner = ptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Duration with the sum of this duration and another (balanced as needed).
|
/// Returns a new Duration with the sum of this duration and another (balanced as needed).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/add
|
///
|
||||||
|
/// See: [Temporal.Duration.add](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/add)
|
||||||
pub fn add(self: Duration, other: Duration) !Duration {
|
pub fn add(self: Duration, other: Duration) !Duration {
|
||||||
return wrapDuration(abi.c.temporal_rs_Duration_add(self._inner, other._inner));
|
return wrapDuration(abi.c.temporal_rs_Duration_add(self._inner, other._inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Duration with the difference between this duration and another (balanced as needed).
|
/// Returns a new Duration with the difference between this duration and another (balanced as needed).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/subtract
|
///
|
||||||
|
/// See: [Temporal.Duration.subtract](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/subtract)
|
||||||
pub fn subtract(self: Duration, other: Duration) !Duration {
|
pub fn subtract(self: Duration, other: Duration) !Duration {
|
||||||
return wrapDuration(abi.c.temporal_rs_Duration_subtract(self._inner, other._inner));
|
return wrapDuration(abi.c.temporal_rs_Duration_subtract(self._inner, other._inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Duration rounded to the given smallest/largest unit and/or balanced.
|
/// Returns a new Duration rounded to the given smallest/largest unit and/or balanced.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/round
|
///
|
||||||
|
/// See: [Temporal.Duration.round](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/round)
|
||||||
pub fn round(self: Duration, options: RoundingOptions) !Duration {
|
pub fn round(self: Duration, options: RoundingOptions) !Duration {
|
||||||
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
||||||
return wrapDuration(abi.c.temporal_rs_Duration_round(self._inner, abi.to.durRoundingOpts(options), rel));
|
return wrapDuration(abi.c.temporal_rs_Duration_round(self._inner, abi.to.durRoundingOpts(options), rel));
|
||||||
|
|
@ -274,7 +295,8 @@ fn roundWithProvider(self: Duration, options: RoundingOptions, relative_to: Rela
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares two durations, returning -1, 0, or 1 if this duration is shorter, equal, or longer than the other.
|
/// Compares two durations, returning -1, 0, or 1 if this duration is shorter, equal, or longer than the other.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/compare
|
///
|
||||||
|
/// See: [Temporal.Duration.compare](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/compare)
|
||||||
pub fn compare(self: Duration, other: Duration, options: CompareOptions) !i8 {
|
pub fn compare(self: Duration, other: Duration, options: CompareOptions) !i8 {
|
||||||
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
||||||
const res = abi.c.temporal_rs_Duration_compare(self._inner, other._inner, rel);
|
const res = abi.c.temporal_rs_Duration_compare(self._inner, other._inner, rel);
|
||||||
|
|
@ -288,7 +310,8 @@ fn compareWithProvider(self: Duration, other: Duration, relative_to: RelativeTo,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the total value of the duration in the specified unit.
|
/// Returns the total value of the duration in the specified unit.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/total
|
///
|
||||||
|
/// See: [Temporal.Duration.total](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/total)
|
||||||
pub fn total(self: Duration, options: TotalOptions) !f64 {
|
pub fn total(self: Duration, options: TotalOptions) !f64 {
|
||||||
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
const rel = if (options.relative_to) |r| abi.to.durRelativeTo(r) else abi.c.RelativeTo{ .date = null, .zoned = null };
|
||||||
const res = abi.c.temporal_rs_Duration_total(self._inner, abi.to.unit(options.unit).?, rel);
|
const res = abi.c.temporal_rs_Duration_total(self._inner, abi.to.unit(options.unit).?, rel);
|
||||||
|
|
@ -303,7 +326,8 @@ fn totalWithProvider(self: Duration, options: TotalOptions, provider: *const abi
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string representing this duration in the ISO 8601 format.
|
/// Returns a string representing this duration in the ISO 8601 format.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toString
|
///
|
||||||
|
/// See: [Temporal.Duration.toString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toString)
|
||||||
pub fn toString(self: Duration, allocator: std.mem.Allocator, options: ToStringRoundingOptions) ![]u8 {
|
pub fn toString(self: Duration, allocator: std.mem.Allocator, options: ToStringRoundingOptions) ![]u8 {
|
||||||
var write = abi.DiplomatWrite.init(allocator);
|
var write = abi.DiplomatWrite.init(allocator);
|
||||||
defer write.deinit();
|
defer write.deinit();
|
||||||
|
|
@ -315,14 +339,16 @@ pub fn toString(self: Duration, allocator: std.mem.Allocator, options: ToStringR
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string representing this duration in the ISO 8601 format (same as toString). Intended for JSON serialization.
|
/// Returns a string representing this duration in the ISO 8601 format (same as toString). Intended for JSON serialization.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toJSON
|
///
|
||||||
|
/// See: [Temporal.Duration.toJSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toJSON)
|
||||||
pub fn toJSON(self: Duration, allocator: std.mem.Allocator) ![]u8 {
|
pub fn toJSON(self: Duration, allocator: std.mem.Allocator) ![]u8 {
|
||||||
return self.toString(allocator, .{});
|
return self.toString(allocator, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string with a language-sensitive representation of this duration.
|
/// Returns a string with a language-sensitive representation of this duration.
|
||||||
/// Not implemented.
|
/// Not implemented.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toLocaleString
|
///
|
||||||
|
/// See: [Temporal.Duration.toLocaleString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration/toLocaleString)
|
||||||
pub fn toLocaleString(self: Duration, allocator: std.mem.Allocator) ![]u8 {
|
pub fn toLocaleString(self: Duration, allocator: std.mem.Allocator) ![]u8 {
|
||||||
_ = self;
|
_ = self;
|
||||||
_ = allocator;
|
_ = allocator;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ const ZonedDateTime = @import("ZonedDateTime.zig");
|
||||||
|
|
||||||
/// The `Temporal.Instant` object represents a unique point in time, with nanosecond precision.
|
/// The `Temporal.Instant` object represents a unique point in time, with nanosecond precision.
|
||||||
/// It is fundamentally represented as the number of nanoseconds since the Unix epoch (midnight at the beginning of January 1, 1970, UTC), without any time zone or calendar system.
|
/// It is fundamentally represented as the number of nanoseconds since the Unix epoch (midnight at the beginning of January 1, 1970, UTC), without any time zone or calendar system.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant
|
///
|
||||||
|
/// See: [Temporal.Instant](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant)
|
||||||
const Instant = @This();
|
const Instant = @This();
|
||||||
|
|
||||||
_inner: *abi.c.Instant,
|
_inner: *abi.c.Instant,
|
||||||
|
|
@ -26,7 +27,8 @@ pub const DifferenceSettings = t.DifferenceSettings;
|
||||||
pub const TimeZone = t.TimeZone;
|
pub const TimeZone = t.TimeZone;
|
||||||
|
|
||||||
/// Options for Instant.toString().
|
/// Options for Instant.toString().
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString
|
///
|
||||||
|
/// See: [Temporal.Instant.toString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString)
|
||||||
pub const ToStringOptions = struct {
|
pub const ToStringOptions = struct {
|
||||||
/// Either an integer from 0 to 9, or null for "auto".
|
/// Either an integer from 0 to 9, or null for "auto".
|
||||||
/// If null (auto), trailing zeros are removed from the fractional seconds.
|
/// If null (auto), trailing zeros are removed from the fractional seconds.
|
||||||
|
|
@ -47,19 +49,22 @@ pub const ToStringOptions = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Construct an Instant from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds).
|
/// Construct an Instant from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochNanoseconds
|
///
|
||||||
|
/// See: [Temporal.Instant.fromEpochNanoseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochNanoseconds)
|
||||||
pub fn init(epoch_ns: i128) !Instant {
|
pub fn init(epoch_ns: i128) !Instant {
|
||||||
return fromEpochNanoseconds(epoch_ns);
|
return fromEpochNanoseconds(epoch_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct an Instant from epoch milliseconds (Temporal.Instant.fromEpochMilliseconds).
|
/// Construct an Instant from epoch milliseconds (Temporal.Instant.fromEpochMilliseconds).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochMilliseconds
|
///
|
||||||
|
/// See: [Temporal.Instant.fromEpochMilliseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochMilliseconds)
|
||||||
pub fn fromEpochMilliseconds(epoch_ms: i64) !Instant {
|
pub fn fromEpochMilliseconds(epoch_ms: i64) !Instant {
|
||||||
return wrapInstant(abi.c.temporal_rs_Instant_from_epoch_milliseconds(epoch_ms));
|
return wrapInstant(abi.c.temporal_rs_Instant_from_epoch_milliseconds(epoch_ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct an Instant from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds).
|
/// Construct an Instant from epoch nanoseconds (Temporal.Instant.fromEpochNanoseconds).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochNanoseconds
|
///
|
||||||
|
/// See: [Temporal.Instant.fromEpochNanoseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/fromEpochNanoseconds)
|
||||||
pub fn fromEpochNanoseconds(epoch_ns: i128) !Instant {
|
pub fn fromEpochNanoseconds(epoch_ns: i128) !Instant {
|
||||||
const parts = abi.toI128Nanoseconds(epoch_ns);
|
const parts = abi.toI128Nanoseconds(epoch_ns);
|
||||||
|
|
||||||
|
|
@ -67,7 +72,8 @@ pub fn fromEpochNanoseconds(epoch_ns: i128) !Instant {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an RFC 9557 string (Temporal.Instant.from) or from another Temporal.Instant.
|
/// Parse an RFC 9557 string (Temporal.Instant.from) or from another Temporal.Instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/from
|
///
|
||||||
|
/// See: [Temporal.Instant.from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/from)
|
||||||
pub fn from(info: anytype) !Instant {
|
pub fn from(info: anytype) !Instant {
|
||||||
const T = @TypeOf(info);
|
const T = @TypeOf(info);
|
||||||
|
|
||||||
|
|
@ -103,51 +109,59 @@ inline fn fromUtf8(text: []const u8) !Instant {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Instant representing this instant moved forward by a given Duration.
|
/// Returns a new Instant representing this instant moved forward by a given Duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/add
|
///
|
||||||
|
/// See: [Temporal.Instant.add](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/add)
|
||||||
pub fn add(self: Instant, duration: *Duration) !Instant {
|
pub fn add(self: Instant, duration: *Duration) !Instant {
|
||||||
return wrapInstant(abi.c.temporal_rs_Instant_add(self._inner, duration._inner));
|
return wrapInstant(abi.c.temporal_rs_Instant_add(self._inner, duration._inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Instant representing this instant moved backward by a given Duration.
|
/// Returns a new Instant representing this instant moved backward by a given Duration.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/subtract
|
///
|
||||||
|
/// See: [Temporal.Instant.subtract](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/subtract)
|
||||||
pub fn subtract(self: Instant, duration: *Duration) !Instant {
|
pub fn subtract(self: Instant, duration: *Duration) !Instant {
|
||||||
return wrapInstant(abi.c.temporal_rs_Instant_subtract(self._inner, duration._inner));
|
return wrapInstant(abi.c.temporal_rs_Instant_subtract(self._inner, duration._inner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a Duration representing the difference from this instant until another instant.
|
/// Returns a Duration representing the difference from this instant until another instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/until
|
///
|
||||||
|
/// See: [Temporal.Instant.until](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/until)
|
||||||
pub fn until(self: Instant, other: Instant, settings: DifferenceSettings) !Duration {
|
pub fn until(self: Instant, other: Instant, settings: DifferenceSettings) !Duration {
|
||||||
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_until(self._inner, other._inner, abi.to.diffsettings(settings)))) orelse return abi.TemporalError.Generic;
|
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_until(self._inner, other._inner, abi.to.diffsettings(settings)))) orelse return abi.TemporalError.Generic;
|
||||||
return .{ ._inner = ptr };
|
return .{ ._inner = ptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a Duration representing the difference from another instant until this instant.
|
/// Returns a Duration representing the difference from another instant until this instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/since
|
///
|
||||||
|
/// See: [Temporal.Instant.since](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/since)
|
||||||
pub fn since(self: Instant, other: Instant, settings: DifferenceSettings) !Duration {
|
pub fn since(self: Instant, other: Instant, settings: DifferenceSettings) !Duration {
|
||||||
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_since(self._inner, other._inner, abi.to.diffsettings(settings)))) orelse return abi.TemporalError.Generic;
|
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_since(self._inner, other._inner, abi.to.diffsettings(settings)))) orelse return abi.TemporalError.Generic;
|
||||||
return .{ ._inner = ptr };
|
return .{ ._inner = ptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new Instant rounded to the given unit.
|
/// Returns a new Instant rounded to the given unit.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/round
|
///
|
||||||
|
/// See: [Temporal.Instant.round](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/round)
|
||||||
pub fn round(self: Instant, options: RoundingOptions) !Instant {
|
pub fn round(self: Instant, options: RoundingOptions) !Instant {
|
||||||
return wrapInstant(abi.c.temporal_rs_Instant_round(self._inner, abi.to.roundingOpts(options)));
|
return wrapInstant(abi.c.temporal_rs_Instant_round(self._inner, abi.to.roundingOpts(options)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares two Instants, returning -1, 0, or 1 if the first is before, equal, or after the second.
|
/// Compares two Instants, returning -1, 0, or 1 if the first is before, equal, or after the second.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/compare
|
///
|
||||||
|
/// See: [Temporal.Instant.compare](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/compare)
|
||||||
pub fn compare(a: Instant, b: Instant) i8 {
|
pub fn compare(a: Instant, b: Instant) i8 {
|
||||||
return abi.c.temporal_rs_Instant_compare(a._inner, b._inner);
|
return abi.c.temporal_rs_Instant_compare(a._inner, b._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if two Instants are equal (same epoch nanoseconds).
|
/// Returns true if two Instants are equal (same epoch nanoseconds).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/equals
|
///
|
||||||
|
/// See: [Temporal.Instant.equals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/equals)
|
||||||
pub fn equals(a: Instant, b: Instant) bool {
|
pub fn equals(a: Instant, b: Instant) bool {
|
||||||
return abi.c.temporal_rs_Instant_equals(a._inner, b._inner);
|
return abi.c.temporal_rs_Instant_equals(a._inner, b._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string representing this instant in the RFC 9557 format, optionally using a time zone.
|
/// Returns a string representing this instant in the RFC 9557 format, optionally using a time zone.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString
|
///
|
||||||
|
/// See: [Temporal.Instant.toString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toString)
|
||||||
pub fn toString(self: Instant, allocator: std.mem.Allocator, opts: ToStringOptions) ![]u8 {
|
pub fn toString(self: Instant, allocator: std.mem.Allocator, opts: ToStringOptions) ![]u8 {
|
||||||
const zone_opt = if (opts.time_zone) |tz| abi.toTimeZoneOption(tz._inner) else abi.toTimeZoneOption(null);
|
const zone_opt = if (opts.time_zone) |tz| abi.toTimeZoneOption(tz._inner) else abi.toTimeZoneOption(null);
|
||||||
const rounding = optsToRounding(opts);
|
const rounding = optsToRounding(opts);
|
||||||
|
|
@ -176,19 +190,22 @@ fn toStringWithProvider(self: Instant, allocator: std.mem.Allocator, provider: *
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string representing this instant in the RFC 9557 format (same as toString). Intended for JSON serialization.
|
/// Returns a string representing this instant in the RFC 9557 format (same as toString). Intended for JSON serialization.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toJSON
|
///
|
||||||
|
/// See: [Temporal.Instant.toJSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toJSON)
|
||||||
pub fn toJSON(self: Instant, allocator: std.mem.Allocator) ![]u8 {
|
pub fn toJSON(self: Instant, allocator: std.mem.Allocator) ![]u8 {
|
||||||
return self.toString(allocator, .{});
|
return self.toString(allocator, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string with a language-sensitive representation of this instant.
|
/// Returns a string with a language-sensitive representation of this instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toLocaleString
|
///
|
||||||
|
/// See: [Temporal.Instant.toLocaleString](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toLocaleString)
|
||||||
pub fn toLocaleString(self: Instant, allocator: std.mem.Allocator) ![]u8 {
|
pub fn toLocaleString(self: Instant, allocator: std.mem.Allocator) ![]u8 {
|
||||||
return self.toString(allocator, .{});
|
return self.toString(allocator, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a ZonedDateTime representing this instant in the specified time zone using the ISO 8601 calendar system.
|
/// Returns a ZonedDateTime representing this instant in the specified time zone using the ISO 8601 calendar system.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toZonedDateTimeISO
|
///
|
||||||
|
/// See: [Temporal.Instant.toZonedDateTimeISO](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toZonedDateTimeISO)
|
||||||
pub fn toZonedDateTimeISO(self: Instant, zone: TimeZone) !ZonedDateTime {
|
pub fn toZonedDateTimeISO(self: Instant, zone: TimeZone) !ZonedDateTime {
|
||||||
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_to_zoned_date_time_iso(self._inner, zone._inner))) orelse return abi.TemporalError.Generic;
|
const ptr = (try abi.extractResult(abi.c.temporal_rs_Instant_to_zoned_date_time_iso(self._inner, zone._inner))) orelse return abi.TemporalError.Generic;
|
||||||
return .{ ._inner = ptr };
|
return .{ ._inner = ptr };
|
||||||
|
|
@ -207,13 +224,15 @@ fn clone(self: Instant) Instant {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of milliseconds since the Unix epoch for this instant.
|
/// Returns the number of milliseconds since the Unix epoch for this instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/epochMilliseconds
|
///
|
||||||
|
/// See: [Temporal.Instant.epochMilliseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/epochMilliseconds)
|
||||||
pub fn epochMilliseconds(self: Instant) i64 {
|
pub fn epochMilliseconds(self: Instant) i64 {
|
||||||
return abi.c.temporal_rs_Instant_epoch_milliseconds(self._inner);
|
return abi.c.temporal_rs_Instant_epoch_milliseconds(self._inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of nanoseconds since the Unix epoch for this instant.
|
/// Returns the number of nanoseconds since the Unix epoch for this instant.
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/epochNanoseconds
|
///
|
||||||
|
/// See: [Temporal.Instant.epochNanoseconds](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/epochNanoseconds)
|
||||||
pub fn epochNanoseconds(self: Instant) i128 {
|
pub fn epochNanoseconds(self: Instant) i128 {
|
||||||
return abi.fromI128Nanoseconds(abi.c.temporal_rs_Instant_epoch_nanoseconds(self._inner));
|
return abi.fromI128Nanoseconds(abi.c.temporal_rs_Instant_epoch_nanoseconds(self._inner));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@ const Duration = @import("Duration.zig");
|
||||||
///
|
///
|
||||||
/// The `Temporal.PlainDate` object represents a calendar date (year, month, day) with no time or time zone.
|
/// The `Temporal.PlainDate` object represents a calendar date (year, month, day) with no time or time zone.
|
||||||
///
|
///
|
||||||
/// The `Temporal.PlainDate` object represents a calendar date (year, month, day) with no time or time zone.
|
/// See: [Temporal.PlainDate](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate)
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate
|
|
||||||
const PlainDate = @This();
|
const PlainDate = @This();
|
||||||
|
|
||||||
/// Internal pointer to the underlying C PlainDate object.
|
/// Internal pointer to the underlying C PlainDate object.
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,7 @@ const Duration = @import("Duration.zig");
|
||||||
///
|
///
|
||||||
/// The `Temporal.PlainDateTime` object represents a calendar date and wall-clock time, but no time zone or offset.
|
/// The `Temporal.PlainDateTime` object represents a calendar date and wall-clock time, but no time zone or offset.
|
||||||
///
|
///
|
||||||
/// - [MDN Temporal.PlainDateTime](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime)
|
/// See: [Temporal.PlainDateTime](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime)
|
||||||
/// The `Temporal.PlainDateTime` object represents a calendar date and wall-clock time, but no time zone or offset.
|
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime
|
|
||||||
const PlainDateTime = @This();
|
const PlainDateTime = @This();
|
||||||
|
|
||||||
/// Internal pointer to the underlying C PlainDateTime object.
|
/// Internal pointer to the underlying C PlainDateTime object.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
/// # Temporal Types and Utilities
|
|
||||||
///
|
|
||||||
/// This file defines core types and options used throughout the Temporal API implementation.
|
|
||||||
///
|
|
||||||
/// - [MDN Temporal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal)
|
|
||||||
/// ## Unit
|
|
||||||
/// Time unit for Temporal operations (e.g., nanosecond, second, day, year).
|
/// Time unit for Temporal operations (e.g., nanosecond, second, day, year).
|
||||||
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
|
|
||||||
pub const Unit = enum {
|
pub const Unit = enum {
|
||||||
auto,
|
auto,
|
||||||
nanosecond,
|
nanosecond,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue