docs: add more exaples
This commit is contained in:
parent
406c7562bb
commit
69311cfc5b
1 changed files with 102 additions and 24 deletions
|
|
@ -7,30 +7,22 @@ pub fn main() !void {
|
||||||
// --- Instant --- //
|
// --- Instant --- //
|
||||||
const instant = try Temporal.Instant.init(1_704_067_200_000_000_000); // 2024-01-01 00:00:00 UTC
|
const instant = try Temporal.Instant.init(1_704_067_200_000_000_000); // 2024-01-01 00:00:00 UTC
|
||||||
defer instant.deinit();
|
defer instant.deinit();
|
||||||
|
|
||||||
std.debug.print(
|
std.debug.print(
|
||||||
\\Instant
|
\\Instant
|
||||||
\\
|
|
||||||
\\ - milliseconds: {}
|
\\ - milliseconds: {}
|
||||||
\\ - nanoseconds: {}
|
\\ - nanoseconds: {}
|
||||||
\\ - toString(): {s}
|
\\ - toString(): {s}
|
||||||
\\
|
\\
|
||||||
\\
|
\\
|
||||||
, .{
|
, .{ instant.epochMilliseconds(), instant.epochNanoseconds(), try instant.toString(allocator, .{}) });
|
||||||
instant.epoch_milliseconds,
|
|
||||||
instant.epoch_nanoseconds,
|
|
||||||
try instant.toString(allocator, .{}),
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Duration --- //
|
// --- Duration --- //
|
||||||
const dur = try Temporal.Duration.from("P1Y2M3DT4H5M6S");
|
const dur = try Temporal.Duration.from("P1Y2M3DT4H5M6S");
|
||||||
defer dur.deinit();
|
defer dur.deinit();
|
||||||
|
|
||||||
std.debug.print(
|
std.debug.print(
|
||||||
\\Duration
|
\\Duration
|
||||||
\\
|
|
||||||
\\ - nanoseconds: {}
|
\\ - nanoseconds: {}
|
||||||
\\ - miliseconds: {}
|
\\ - milliseconds: {}
|
||||||
\\ - seconds: {}
|
\\ - seconds: {}
|
||||||
\\ - minutes: {}
|
\\ - minutes: {}
|
||||||
\\ - hours: {}
|
\\ - hours: {}
|
||||||
|
|
@ -39,20 +31,106 @@ pub fn main() !void {
|
||||||
\\ - months: {}
|
\\ - months: {}
|
||||||
\\ - years: {}
|
\\ - years: {}
|
||||||
\\ - toString(): {s}
|
\\ - toString(): {s}
|
||||||
\\ - total(): {{}}
|
|
||||||
\\
|
\\
|
||||||
\\
|
\\
|
||||||
, .{
|
, .{ dur.nanoseconds(), dur.milliseconds(), dur.seconds(), dur.minutes(), dur.hours(), dur.days(), dur.weeks(), dur.months(), dur.years(), try dur.toString(allocator, .{}) });
|
||||||
dur.nanoseconds(),
|
|
||||||
dur.milliseconds(),
|
// --- Now --- //
|
||||||
dur.seconds(),
|
const now_instant = try Temporal.Now.instant();
|
||||||
dur.minutes(),
|
defer now_instant.deinit();
|
||||||
dur.hours(),
|
const now_date = try Temporal.Now.plainDateISO();
|
||||||
dur.days(),
|
defer now_date.deinit();
|
||||||
dur.weeks(),
|
const now_datetime = try Temporal.Now.plainDateTimeISO();
|
||||||
dur.months(),
|
const now_time = try Temporal.Now.plainTimeISO();
|
||||||
dur.years(),
|
std.debug.print(
|
||||||
try dur.toString(allocator, .{}),
|
\\Now
|
||||||
// try dur.total(.{ .unit = .minute }),
|
\\ - instant: {s}
|
||||||
});
|
\\ - date: {s}
|
||||||
|
\\ - datetime: {s}
|
||||||
|
\\ - time: {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ try now_instant.toString(allocator, .{}), try now_date.toString(allocator, .{}), try now_datetime.toString(allocator, .{}), try now_time.toString(allocator) });
|
||||||
|
|
||||||
|
// --- PlainDate --- //
|
||||||
|
const date = try Temporal.PlainDate.init(2024, 2, 2);
|
||||||
|
defer date.deinit();
|
||||||
|
std.debug.print(
|
||||||
|
\\PlainDate
|
||||||
|
\\ - year: {}
|
||||||
|
\\ - month: {}
|
||||||
|
\\ - day: {}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ date.year(), date.month(), date.day(), try date.toString(allocator, .{}) });
|
||||||
|
|
||||||
|
// --- PlainDateTime --- //
|
||||||
|
const dt = try Temporal.PlainDateTime.init(2024, 2, 2, 13, 45, 30, 123, 456, 789);
|
||||||
|
std.debug.print(
|
||||||
|
\\PlainDateTime
|
||||||
|
\\ - year: {}
|
||||||
|
\\ - month: {}
|
||||||
|
\\ - day: {}
|
||||||
|
\\ - hour: {}
|
||||||
|
\\ - minute: {}
|
||||||
|
\\ - second: {}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(), try dt.toString(allocator, .{}) });
|
||||||
|
|
||||||
|
// --- PlainMonthDay --- //
|
||||||
|
const md = try Temporal.PlainMonthDay.init(2, 2, null);
|
||||||
|
std.debug.print(
|
||||||
|
\\PlainMonthDay
|
||||||
|
\\ - monthCode: {s}
|
||||||
|
\\ - day: {}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ try md.monthCode(allocator), md.day(), try md.toString(allocator) });
|
||||||
|
|
||||||
|
// --- PlainTime --- //
|
||||||
|
const tm = try Temporal.PlainTime.init(13, 45, 30, 123, 456, 789);
|
||||||
|
std.debug.print(
|
||||||
|
\\PlainTime
|
||||||
|
\\ - hour: {}
|
||||||
|
\\ - minute: {}
|
||||||
|
\\ - second: {}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ tm.hour(), tm.minute(), tm.second(), try tm.toString(allocator) });
|
||||||
|
|
||||||
|
// --- PlainYearMonth --- //
|
||||||
|
const ym = try Temporal.PlainYearMonth.init(2024, 2, null);
|
||||||
|
std.debug.print(
|
||||||
|
\\PlainYearMonth
|
||||||
|
\\ - year: {}
|
||||||
|
\\ - month: {}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ ym.year(), ym.month(), try ym.toString(allocator) });
|
||||||
|
|
||||||
|
// --- ZonedDateTime --- //
|
||||||
|
const tz = try Temporal.ZonedDateTime.TimeZone.init("UTC");
|
||||||
|
// Example: 2024-02-02T13:45:30.123456789Z in nanoseconds since epoch
|
||||||
|
const zdt_epoch_ns: i128 = 1706881530123456789;
|
||||||
|
const zdt = try Temporal.ZonedDateTime.fromEpochNanoseconds(zdt_epoch_ns, tz);
|
||||||
|
defer zdt.deinit();
|
||||||
|
std.debug.print(
|
||||||
|
\\ZonedDateTime
|
||||||
|
\\ - year: {}
|
||||||
|
\\ - month: {}
|
||||||
|
\\ - day: {}
|
||||||
|
\\ - hour: {}
|
||||||
|
\\ - minute: {}
|
||||||
|
\\ - second: {}
|
||||||
|
\\ - timeZone: {s}
|
||||||
|
\\ - toString(): {s}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{ zdt.year(), zdt.month(), zdt.day(), zdt.hour(), zdt.minute(), zdt.second(), try zdt.timeZoneId(allocator), try zdt.toString(allocator, .{}) });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue