### Manual Now Implementation with EmptyHostSystem Source: https://github.com/boa-dev/temporal/blob/main/README.md Implement `Now` using `EmptyHostSystem` for a basic time and timezone setup. This example relies on the `compiled_data` feature for timezone data. ```rust use temporal_rs::{Instant, now::Now, host::EmptyHostSystem}; // The empty host system is a system implementation HostHooks that always // returns the UNIX_EPOCH and the "+00:00" time zone. let now = Now::new(EmptyHostSystem); let time_zone = now.time_zone().unwrap(); assert_eq!(time_zone.identifier().unwrap(), "+00:00"); let now = Now::new(EmptyHostSystem); assert_eq!(now.instant(), Instant::try_new(0)); ``` -------------------------------- ### Get Current Instant and ZonedDateTime Source: https://github.com/boa-dev/temporal/blob/main/README.md This example demonstrates how to get the current instant and ZonedDateTime using the Temporal.now() method. It requires the `sys` and `compiled_data` feature flags. The `ZonedDateTime` is then created from the current instant and compared. ```rust use core::cmp::Ordering; use temporal_rs::{Temporal, Calendar, ZonedDateTime}; let current_instant = Temporal::now().instant().unwrap(); let current_zoned_date_time = Temporal::now().zoned_date_time_iso(None).unwrap(); /// Create a `ZonedDateTime` from the requested instant. let zoned_date_time_from_instant = ZonedDateTime::try_new( current_instant.as_i128(), *current_zoned_date_time.time_zone(), Calendar::ISO, ).unwrap(); // The two `ZonedDateTime` will be equal down to the second. assert_eq!(current_zoned_date_time.year(), zoned_date_time_from_instant.year()); assert_eq!(current_zoned_date_time.month(), zoned_date_time_from_instant.month()); assert_eq!(current_zoned_date_time.day(), zoned_date_time_from_instant.day()); assert_eq!(current_zoned_date_time.hour(), zoned_date_time_from_instant.hour()); assert_eq!(current_zoned_date_time.minute(), zoned_date_time_from_instant.minute()); assert_eq!(current_zoned_date_time.second(), zoned_date_time_from_instant.second()); // The `Instant` reading that occurred first will be less than the ZonedDateTime // reading assert_eq!( zoned_date_date_time_from_instant.compare_instant(¤t_zoned_date_time), Ordering::Less ); ``` -------------------------------- ### Access System Time with Temporal.rs Now Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates how to get the current system time as an Instant and ZonedDateTime. Requires 'sys' and 'compiled_data' features. Also shows a custom implementation using EmptyHostSystem. ```rust #[cfg(all(feature = "sys", feature = "compiled_data"))] { use temporal_rs::{Temporal, Calendar, ZonedDateTime}; use core::cmp::Ordering; // Get current instant let current_instant = Temporal::now().instant().unwrap(); // Get current zoned date time in system timezone let current_zdt = Temporal::now().zoned_date_time_iso(None).unwrap(); // Create ZonedDateTime from the instant let zdt_from_instant = ZonedDateTime::try_new( current_instant.as_i128(), *current_zdt.time_zone(), Calendar::ISO, ).unwrap(); // Both represent the same moment (down to the second) assert_eq!(current_zdt.year(), zdt_from_instant.year()); assert_eq!(current_zdt.month(), zdt_from_instant.month()); assert_eq!(current_zdt.day(), zdt_from_instant.day()); assert_eq!(current_zdt.hour(), zdt_from_instant.hour()); assert_eq!(current_zdt.minute(), zdt_from_instant.minute()); assert_eq!(current_zdt.second(), zdt_from_instant.second()); // For custom implementations without system access use temporal_rs::{Instant, now::Now, host::EmptyHostSystem}; let now = Now::new(EmptyHostSystem); let time_zone = now.time_zone().unwrap(); assert_eq!(time_zone.identifier().unwrap(), "+00:00"); assert_eq!(now.instant(), Instant::try_new(0)); // Returns Unix epoch } ``` -------------------------------- ### Example Test Failure Output Source: https://github.com/boa-dev/temporal/blob/main/docs/testing.md This is an example of the output seen when a specific test fails, including the test path and the uncaught error. ```txt Getting last commit on 'HEAD' branch Loading the test suite... Test loaded, starting... /home/user/Projects/boa/test262/test/built-ins/Temporal/Instant/compare/argument-string-limits.js: starting /home/user/Projects/boa/test262/test/built-ins/Temporal/Instant/compare/argument-string-limits.js: Failed /home/user/Projects/boa/test262/test/built-ins/Temporal/Instant/compare/argument-string-limits.js: result text Uncaught RangeError: Instant nanoseconds are not within a valid epoch range. ``` -------------------------------- ### Run tzif-inspect Utility Source: https://github.com/boa-dev/temporal/blob/main/tools/tzif-inspect/README.md Execute the tzif-inspect tool to inspect a specific tzdb entry, such as 'America/Los_Angeles'. This command requires the Rust toolchain to be installed. ```sh cargo run -p tzif-inspect -- America/Los_Angeles ``` -------------------------------- ### Duration Arithmetic (Addition) Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates adding two `Duration` objects together to get a combined duration. ```rust use temporal_rs::Duration; use core::str::FromStr; // Duration arithmetic let commute = Duration::from_str("PT45M").unwrap(); let lunch = Duration::from_str("PT1H").unwrap(); let total = commute.add(&lunch).unwrap(); assert_eq!(total.hours(), 1); assert_eq!(total.minutes(), 45); ``` -------------------------------- ### Duration Properties (is_zero, abs, negated) Source: https://context7.com/boa-dev/temporal/llms.txt Explains how to check if a duration is zero, get its absolute value, and negate its value. ```rust use temporal_rs::Duration; use core::str::FromStr; // Duration properties let complex = Duration::from_str("P1Y2M3DT4H5M6.789S").unwrap(); assert!(!complex.is_zero()); let abs_duration = complex.abs(); let negated = complex.negated(); assert_eq!(negated.years(), -1); ``` -------------------------------- ### Date Arithmetic with Duration and Overflow Handling Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates adding a month `Duration` to a `PlainDate`, handling potential overflow using `Overflow::Constrain`. This example highlights leap year considerations. ```rust use temporal_rs::{Duration, PlainDate}; use temporal_rs::options::Overflow; use core::str::FromStr; // Date arithmetic with durations (handles calendar quirks) let jan_31_2024 = PlainDate::try_new_iso(2024, 1, 31).unwrap(); // leap year let one_month = Duration::from_str("P1M").unwrap(); let feb_2024 = jan_31_2024.add(&one_month, Some(Overflow::Constrain)).unwrap(); assert_eq!(feb_2024.day(), 29); // Feb 29 in leap year ``` -------------------------------- ### Create Instant from Epoch Milliseconds Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to create an `Instant` from milliseconds since the Unix epoch, a common format in web applications. ```rust use temporal_rs::Instant; // Create from epoch milliseconds (common in web applications) let web_timestamp = Instant::from_epoch_milliseconds(1609459200000).unwrap(); assert_eq!(web_timestamp.epoch_nanoseconds().as_i128(), 1609459200000000000); ``` -------------------------------- ### Create and Use Instant from Epoch Nanoseconds Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates creating an `Instant` from nanoseconds since the Unix epoch and verifying its millisecond and nanosecond values. ```rust use temporal_rs::{Instant, Duration}; use core::str::FromStr; // Create from epoch nanoseconds let instant = Instant::try_new(1609459200000000000).unwrap(); // 2021-01-01T00:00:00Z assert_eq!(instant.epoch_milliseconds(), 1609459200000); assert_eq!(instant.epoch_nanoseconds().as_i128(), 1609459200000000000); ``` -------------------------------- ### Manual Now Implementation without Default Features Source: https://github.com/boa-dev/temporal/blob/main/README.md Implement `Now` using `EmptyHostSystem` and `CompiledTzdbProvider` without relying on default features. This provides more control over timezone data sourcing. ```rust use temporal_rs::{Instant, now::Now, host::EmptyHostSystem}; use timezone_provider::tzif::CompiledTzdbProvider; let provider = CompiledTzdbProvider::default(); // The empty host system is a system implementation HostHooks that always // returns the UNIX_EPOCH and the "+00:00" time zone. let now = Now::new(EmptyHostSystem); let time_zone = now.time_zone_with_provider(&provider).unwrap(); assert_eq!(time_zone.identifier_with_provider(&provider).unwrap(), "+00:00"); let now = Now::new(EmptyHostSystem); assert_eq!(now.instant(), Instant::try_new(0)); ``` -------------------------------- ### Check Project Dependencies Source: https://github.com/boa-dev/temporal/blob/main/CONTRIBUTING.md Use this command to check the project's dependencies. ```bash cargo run -p depcheck ``` -------------------------------- ### Create and Manipulate PlainDate in Rust Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates creating PlainDate instances using ISO format, parsing from strings, performing date arithmetic by adding durations, calculating differences between dates, and converting between calendars like ISO and Japanese. ```rust use temporal_rs::{PlainDate, Duration, Calendar}; use core::str::FromStr; // Create a date using the ISO calendar let christmas = PlainDate::try_new_iso(2024, 12, 25).unwrap(); assert_eq!(christmas.year(), 2024); assert_eq!(christmas.month(), 12); assert_eq!(christmas.day(), 25); // Parse from ISO 8601 string let date = PlainDate::from_str("2024-03-15").unwrap(); assert_eq!(date.year(), 2024); assert_eq!(date.month(), 3); assert_eq!(date.day(), 15); // Date arithmetic - add one month let start = PlainDate::try_new_iso(2024, 1, 15).unwrap(); let later = start.add(&Duration::from_str("P1M").unwrap(), None).unwrap(); assert_eq!(later.month(), 2); assert_eq!(later.day(), 15); // Calculate difference between dates let new_year = PlainDate::try_new_iso(2024, 1, 1).unwrap(); let diff = new_year.until(&start, Default::default()).unwrap(); assert_eq!(diff.days(), 14); // Calendar conversion (ISO to Japanese) use tinystr::tinystr; let iso_date = PlainDate::try_new_iso(2025, 3, 3).unwrap(); let japanese_date = iso_date.with_calendar(Calendar::JAPANESE); assert_eq!(japanese_date.era(), Some(tinystr!(16, "reiwa"))); assert_eq!(japanese_date.era_year(), Some(7)); ``` -------------------------------- ### Run intl402 Temporal Test Suite with Boa Tester Source: https://github.com/boa-dev/temporal/blob/main/docs/testing.md Execute the intl402 Temporal test suite using the boa_tester binary. This requires the intl402 Temporal tests to be available. ```bash cargo run --bin boa_tester -- run -vv --console -s test/intl402/Temporal ``` -------------------------------- ### Create and Manipulate PlainTime in Rust Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to create precise PlainTime instances, parse time strings, perform time arithmetic by adding durations, calculate differences between times, modify specific fields using PartialTime, and round times to a specified unit. ```rust use temporal_rs::{PlainTime, Duration, partial::PartialTime}; use core::str::FromStr; // Create a precise time let time = PlainTime::try_new(14, 30, 45, 123, 456, 789).unwrap(); assert_eq!(time.hour(), 14); assert_eq!(time.minute(), 30); assert_eq!(time.second(), 45); assert_eq!(time.millisecond(), 123); assert_eq!(time.microsecond(), 456); assert_eq!(time.nanosecond(), 789); // Parse ISO 8601 time string let parsed = PlainTime::from_str("14:30:45.123456789").unwrap(); assert_eq!(parsed.hour(), 14); // Time arithmetic - add 2 hours 30 minutes let noon = PlainTime::from_str("12:30:00").unwrap(); let later = noon.add(&Duration::from_str("PT2H30M").unwrap()).unwrap(); assert_eq!(later.hour(), 15); assert_eq!(later.minute(), 0); // Calculate difference between times let earlier = PlainTime::from_str("10:00:00").unwrap(); let duration = earlier.until(&noon, Default::default()).unwrap(); assert_eq!(duration.hours(), 2); assert_eq!(duration.minutes(), 30); // Modify specific fields using PartialTime let partial = PartialTime::new().with_minute(Some(15)); let modified = noon.with(partial, None).unwrap(); assert_eq!(modified.hour(), 12); // unchanged assert_eq!(modified.minute(), 15); // changed // Round to nearest minute use temporal_rs::options::{Unit, RoundingOptions}; let precise = PlainTime::from_str("14:23:47.789").unwrap(); let mut opts = RoundingOptions::default(); opts.smallest_unit = Some(Unit::Minute); let rounded = precise.round(opts).unwrap(); assert_eq!(rounded.minute(), 24); assert_eq!(rounded.second(), 0); ``` -------------------------------- ### Configure Date/Time Operation Options in Rust Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates how to use Overflow, RoundingOptions, and DifferenceSettings for date/time operations. Requires importing specific types from temporal_rs and core::str::FromStr. ```rust use temporal_rs::{PlainDate, Duration, PlainTime}; use temporal_rs::options::{ Overflow, RoundingOptions, RoundingMode, RoundingIncrement, Unit, DifferenceSettings, Disambiguation }; use core::str::FromStr; // Overflow options - how to handle invalid dates let jan_31 = PlainDate::try_new_iso(2024, 1, 31).unwrap(); let one_month = Duration::from_str("P1M").unwrap(); // Constrain: clamp to valid range (Feb 29 in leap year) let constrained = jan_31.add(&one_month, Some(Overflow::Constrain)).unwrap(); assert_eq!(constrained.day(), 29); // Reject: return error for invalid dates // let rejected = jan_31.add(&one_month, Some(Overflow::Reject)); // Would error // Rounding options let time = PlainTime::from_str("14:23:47.789").unwrap(); let opts = RoundingOptions { smallest_unit: Some(Unit::Minute), rounding_mode: Some(RoundingMode::HalfExpand), increment: Some(RoundingIncrement::try_new(15).unwrap()), ..Default::default() }; let rounded = time.round(opts).unwrap(); assert_eq!(rounded.minute(), 30); // Rounded to nearest 15 minutes // Difference settings with rounding let earlier = PlainDate::try_new_iso(2019, 1, 8).unwrap(); let later = PlainDate::try_new_iso(2021, 9, 7).unwrap(); let settings = DifferenceSettings { smallest_unit: Some(Unit::Month), rounding_mode: Some(RoundingMode::HalfExpand), increment: Some(RoundingIncrement::try_new(1).unwrap()), largest_unit: Some(Unit::Year), }; let diff = later.since(&earlier, settings).unwrap(); // Rounding modes available: // - Ceil: Round toward positive infinity // - Floor: Round toward negative infinity // - Trunc: Round toward zero // - HalfExpand: Round half away from zero (common "round") // - HalfCeil: Round half toward positive infinity // - HalfFloor: Round half toward negative infinity // - HalfTrunc: Round half toward zero // - HalfEven: Round half to nearest even (banker's rounding) ``` -------------------------------- ### Run Temporal Built-in Test Suite with Boa Tester Source: https://github.com/boa-dev/temporal/blob/main/docs/testing.md Execute the built-in Temporal test suite using the boa_tester binary. Ensure Boa's Temporal builtin is implemented before running. ```bash cargo run --bin boa_tester -- run -vv --console -s test/built-ins/Temporal ``` -------------------------------- ### Specify and Run ZonedDateTime.prototype.add Tests Source: https://github.com/boa-dev/temporal/blob/main/docs/testing.md Run tests specifically for the ZonedDateTime.prototype.add method by qualifying the path in the boa_tester command. ```bash cargo run --bin boa_tester -- run -vv --console -s test/built-ins/Temporal/ZonedDateTime/prototype/add ``` -------------------------------- ### Instant Limits and Range Checks Source: https://context7.com/boa-dev/temporal/llms.txt Illustrates the approximate limits of `Instant` representation, showing that values outside the supported range will result in an error. ```rust use temporal_rs::Instant; // Instant limits (approximately 100 million days before/after Unix epoch) let max_ns = 8_640_000_000_000_000_000_000i128; let max_instant = Instant::try_new(max_ns).unwrap(); assert!(Instant::try_new(max_ns + 1).is_err()); // Out of range ``` -------------------------------- ### Parse ISO 8601 Instant String Source: https://context7.com/boa-dev/temporal/llms.txt Illustrates parsing an ISO 8601 formatted string with timezone information into an `Instant` object. ```rust use temporal_rs::Instant; use core::str::FromStr; // Parse ISO 8601 instant string (must include timezone info) let parsed = Instant::from_str("2024-03-15T14:30:45.123Z").unwrap(); assert_eq!(parsed.epoch_milliseconds(), 1710513045123); ``` -------------------------------- ### Compile TZif Files Source: https://github.com/boa-dev/temporal/blob/main/tools/zoneinfo-test-gen/README.md Use this command to compile new tzif files from downloaded IANA tzdata. Specify output directory and path to zoneinfo files. ```bash zic [OPTIONS] -d ``` -------------------------------- ### Round Instant to Nearest Second Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates rounding an `Instant` to the nearest second using `RoundingOptions`. Ensure `smallest_unit` is set to `Unit::Second`. ```rust use temporal_rs::{Instant, options::{RoundingOptions, Unit}}; // Round to nearest second let precise = Instant::try_new(1609459245123456789).unwrap(); let mut opts = RoundingOptions::default(); opts.smallest_unit = Some(Unit::Second); let rounded = precise.round(opts).unwrap(); assert_eq!(rounded.epoch_nanoseconds().as_i128() % 1_000_000_000, 0); ``` -------------------------------- ### Use Temporal.rs Calendars Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates creating dates with different calendars, converting between them, parsing calendar strings, and accessing calendar-derived properties. ```rust use temporal_rs::{PlainDate, Calendar}; use tinystr::tinystr; use core::str::FromStr; // Available calendar constants let iso = Calendar::ISO; // ISO 8601 (default) let gregorian = Calendar::GREGORIAN; let japanese = Calendar::JAPANESE; let hebrew = Calendar::HEBREW; let chinese = Calendar::CHINESE; let buddhist = Calendar::BUDDHIST; let persian = Calendar::PERSIAN; // Create date with specific calendar let date = PlainDate::try_new(2025, 3, 3, Calendar::ISO).unwrap(); // Convert between calendars let japanese_date = date.with_calendar(Calendar::JAPANESE); assert_eq!(japanese_date.era(), Some(tinystr!(16, "reiwa"))); assert_eq!(japanese_date.era_year(), Some(7)); assert_eq!(japanese_date.month(), 3); // Parse calendar from string let cal = Calendar::try_from_utf8(b"japanese").unwrap(); let date_jp = PlainDate::try_new(7, 3, 3, cal).unwrap(); // Reiwa 7 // Calendar-derived properties let iso_date = PlainDate::try_new_iso(2024, 12, 25).unwrap(); assert_eq!(iso_date.day_of_week(), 3); // Wednesday (ISO: 1=Monday) assert_eq!(iso_date.day_of_year(), 360); assert_eq!(iso_date.days_in_month(), 31); assert_eq!(iso_date.days_in_year(), 366); // 2024 is a leap year assert!(iso_date.in_leap_year()); assert_eq!(iso_date.months_in_year(), 12); ``` -------------------------------- ### Instant Arithmetic with Duration Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates adding a `Duration` to an `Instant` to calculate a future point in time. Note that only time-based durations are supported for `Instant` arithmetic. ```rust use temporal_rs::{Instant, Duration}; use core::str::FromStr; // Instant arithmetic (only time durations, not date durations) let instant = Instant::try_new(1609459200000000000).unwrap(); // 2021-01-01T00:00:00Z let later = instant.add(&Duration::from_str("PT1H30M").unwrap()).unwrap(); let expected_ns = 1609459200000000000 + (1 * 3600 + 30 * 60) * 1_000_000_000i128; assert_eq!(later.epoch_nanoseconds().as_i128(), expected_ns); ``` -------------------------------- ### Parse and Format ISO 8601 Strings in Rust Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to parse and format date, time, and datetime values using ISO 8601 strings with different precision and calendar options. Includes parsing duration strings. ```rust use temporal_rs::{PlainDateTime, PlainDate, Duration}; use temporal_rs::options::{DisplayCalendar, ToStringRoundingOptions}; use temporal_rs::parsers::Precision; use core::str::FromStr; // Parse various ISO 8601 formats let date = PlainDate::from_str("2024-03-15").unwrap(); let date_with_cal = PlainDate::from_str("2024-03-15[u-ca=iso8601]").unwrap(); let datetime = PlainDateTime::from_str("2024-03-15T14:30:45.123456789").unwrap(); // Format with different precision let dt = PlainDateTime::try_new_iso(1976, 11, 18, 15, 23, 30, 123, 400, 0).unwrap(); // No fractional seconds let opts = ToStringRoundingOptions { precision: Precision::Digit(0), ..Default::default() }; let s = dt.to_ixdtf_string(opts, DisplayCalendar::Auto).unwrap(); assert_eq!(&s, "1976-11-18T15:23:30"); // 3 decimal places (milliseconds) let opts = ToStringRoundingOptions { precision: Precision::Digit(3), ..Default::default() }; let s = dt.to_ixdtf_string(opts, DisplayCalendar::Auto).unwrap(); assert_eq!(&s, "1976-11-18T15:23:30.123"); // 9 decimal places (nanoseconds) let opts = ToStringRoundingOptions { precision: Precision::Digit(9), ..Default::default() }; let s = dt.to_ixdtf_string(opts, DisplayCalendar::Auto).unwrap(); assert_eq!(&s, "1976-11-18T15:23:30.123400000"); // Display calendar annotation let s = date.to_ixdtf_string(DisplayCalendar::Always); assert!(s.contains("[u-ca=iso8601]")); // Parse durations let d = Duration::from_str("P1Y2M3DT4H5M6.789S").unwrap(); let d_negative = Duration::from_str("-P1D").unwrap(); let d_time_only = Duration::from_str("PT2H30M").unwrap(); ``` -------------------------------- ### Generate zoneinfo Test Data Source: https://github.com/boa-dev/temporal/blob/main/tools/zoneinfo-test-gen/README.md Run this command to generate zoneinfo test data for a given IANA identifier. It reads from the local UNIX zoneinfo directory by default. ```bash cargo run -p zoneinfo-test-gen ``` -------------------------------- ### Create Duration with Specific Components Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to construct a `Duration` object by specifying weeks and days, with zero time components. ```rust use temporal_rs::Duration; // Create a duration with specific components let vacation = Duration::new( 0, 0, 2, 3, // 2 weeks and 3 days 0, 0, 0, // no time components 0, 0, 0 // no subsecond components ).unwrap(); assert_eq!(vacation.weeks(), 2); assert_eq!(vacation.days(), 3); ``` -------------------------------- ### Parse and Compile Zoneinfo Files in Rust Source: https://github.com/boa-dev/temporal/blob/main/zoneinfo/README.md Use this snippet to parse zoneinfo files from a directory and then compile them. Ensure the path points to the directory containing the tzdata files. This functionality is experimental and may change. ```rust use std::path::Path; use zoneinfo_rs::{ZoneInfoData, ZoneInfoCompiler}; // Below assumes we are in the parent directory of `tzdata`. let zoneinfo_filepath = Path::new("./tzdata/"); // Parse and then compile the files from the directory. let parsed_data = ZoneInfoData::from_zoneinfo_directory(zoneinfo_filepath)?; let _compiled_data = ZoneInfoCompiler::new(parsed_data).build(); ``` -------------------------------- ### Fetching Year Value with Custom Calendar Source: https://github.com/boa-dev/temporal/blob/main/docs/design/initial-api-concept.md Illustrates fetching a year value when a custom calendar is used but no additional context is required. ```rust let year_value = Date.year(&mut ()); ``` -------------------------------- ### Calculate Time Difference Between Instants Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to calculate the time difference between two `Instant` objects using the `until` method, returning a `Duration`. ```rust use temporal_rs::{Instant, Duration}; // Calculate difference between instants let instant = Instant::try_new(1609459200000000000).unwrap(); // 2021-01-01T00:00:00Z let earlier = Instant::try_new(1609459200000000000 - 3600_000_000_000).unwrap(); let duration = earlier.until(&instant, Default::default()).unwrap(); assert_eq!(duration.seconds(), 3600); ``` -------------------------------- ### Convert Date Calendar in Rust Source: https://github.com/boa-dev/temporal/blob/main/README.md Demonstrates converting a date from the ISO calendar to the Japanese calendar using `temporal_rs`. Ensure the `Calendar` enum and `PlainDate` type are imported. ```rust use temporal_rs::{PlainDate, Calendar}; use tinystr::tinystr; use core::str::FromStr; // Create a date with an ISO calendar let iso8601_date = PlainDate::try_new_iso(2025, 3, 3).unwrap(); // Create a new date with the japanese calendar let japanese_date = iso8601_date.with_calendar(Calendar::JAPANESE); assert_eq!(japanese_date.era(), Some(tinystr!(16, "reiwa"))); assert_eq!(japanese_date.era_year(), Some(7)); assert_eq!(japanese_date.month(), 3) ``` -------------------------------- ### Core TimeZoneProvider API for ZonedDateTime Source: https://github.com/boa-dev/temporal/blob/main/docs/architecture.md Demonstrates the Provider API for ZonedDateTime, allowing users to supply a TimeZoneProvider for custom time zone data sourcing in calculations. This is primarily for engine implementors. ```rust impl ZonedDateTime { pub fn day_with_provider(&self, provider: &(impl TimeZoneProvider + ?Sized)) -> TemporalResult { // Code goes here. } } ``` -------------------------------- ### Handle TimeZones with Temporal.rs Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to create TimeZone objects from IANA names or UTC offsets and use them with ZonedDateTime. Requires the 'compiled_data' feature. ```rust #[cfg(feature = "compiled_data")] { use temporal_rs::{TimeZone, ZonedDateTime, Calendar, Instant}; // Create UTC timezone let utc = TimeZone::utc(); assert_eq!(utc.identifier().unwrap(), "UTC"); // Create from IANA timezone name let new_york = TimeZone::try_from_str("America/New_York").unwrap(); let tokyo = TimeZone::try_from_str("Asia/Tokyo").unwrap(); let london = TimeZone::try_from_str("Europe/London").unwrap(); // Create from UTC offset let offset_zone = TimeZone::try_from_str("+05:30").unwrap(); // Use timezone with ZonedDateTime let instant = Instant::try_new(1609459200000000000).unwrap(); let zdt_ny = ZonedDateTime::try_new_from_instant( instant, new_york, Calendar::default(), ).unwrap(); let zdt_tokyo = ZonedDateTime::try_new_from_instant( instant, tokyo, Calendar::default(), ).unwrap(); // Same instant, different local times assert_eq!(zdt_ny.hour(), 19); // 7 PM EST assert_eq!(zdt_tokyo.hour(), 9); // 9 AM JST (next day) } ``` -------------------------------- ### Configure temporal_rs Feature Flags in Cargo.toml Source: https://context7.com/boa-dev/temporal/llms.txt Illustrates how to enable specific features for the temporal_rs crate in your Cargo.toml file to control functionality like timezone data embedding and system time access. ```toml [dependencies] temporal_rs = { version = "0.2.3", features = ["compiled_data", "sys"] } # Available features: # - default: includes "sys-local" # - compiled_data: embeds timezone data, enables convenience APIs # - sys: provides system time access (requires std) # - sys-local: includes sys + local timezone detection # - tzdb: enables filesystem-based timezone provider # - std: enables standard library features ``` -------------------------------- ### Generate Changelog with Git Cliff Source: https://github.com/boa-dev/temporal/blob/main/docs/release.md Use git cliff to update the CHANGELOG.md file. Specify the previous and release tags to generate the changelog entries for the new release. This command prepends the new entries to the existing changelog. ```bash git cliff $PREVIOUS_TAG.. --tag $RELEASE_TAG --prepend CHANGELOG.md ``` ```bash git cliff v0.0.8.. --tag v0.0.9 --prepend CHANGELOG.md ``` -------------------------------- ### Switch Zoneinfo Data Form Source: https://github.com/boa-dev/temporal/blob/main/tools/zoneinfo-test-gen/README.md This awk script switches zoneinfo files between 'vanguard' and 'rearguard' data forms. It takes the zoneinfo file as input and outputs to stdout. ```awk awk -v DATAFORM=rearguard -f ziguard.awk > output ``` -------------------------------- ### Parse ISO 8601 Duration String Source: https://context7.com/boa-dev/temporal/llms.txt Demonstrates parsing a complex ISO 8601 duration string that includes years, months, days, hours, minutes, and seconds. ```rust use temporal_rs::Duration; use core::str::FromStr; // Parse ISO 8601 duration strings let complex = Duration::from_str("P1Y2M3DT4H5M6.789S").unwrap(); assert_eq!(complex.years(), 1); assert_eq!(complex.months(), 2); assert_eq!(complex.days(), 3); assert_eq!(complex.hours(), 4); assert_eq!(complex.minutes(), 5); assert_eq!(complex.seconds(), 6); ``` -------------------------------- ### Compiled ZonedDateTime API with Default Provider Source: https://github.com/boa-dev/temporal/blob/main/docs/architecture.md Shows the simplified ZonedDateTime API available with the 'compiled' feature flag. It includes a default provider implementation, removing the need for general users to manage TimeZoneProvider. ```rust impl ZonedDateTime { pub fn day(&self) -> TemporalResult { // Code goes here. } } ``` -------------------------------- ### Update FFI Bindings with Diplomat Source: https://github.com/boa-dev/temporal/blob/main/CONTRIBUTING.md Run this command to update FFI bindings if changes are made to temporal_capi that affect the public API. ```bash cargo run -p diplomat-gen ``` -------------------------------- ### Parse and Convert ZonedDateTime in Rust Source: https://github.com/boa-dev/temporal/blob/main/README.md Shows how to parse a string into a `ZonedDateTime` and convert it to a different timezone using the `temporal_rs` library. This requires the `compiled_data` feature flag and imports for `ZonedDateTime`, `TimeZone`, and options. ```rust use temporal_rs::{ZonedDateTime, TimeZone}; use temporal_rs::options::{Disambiguation, OffsetDisambiguation}; let zdt = ZonedDateTime::from_utf8( b"2025-03-01T11:16:10Z[America/Chicago][u-ca=iso8601]", Disambiguation::Compatible, OffsetDisambiguation::Reject ).unwrap(); assert_eq!(zdt.year(), 2025); assert_eq!(zdt.month(), 3); assert_eq!(zdt.day(), 1); // Using Z and a timezone projects a UTC datetime into the timezone. assert_eq!(zdt.hour(), 5); assert_eq!(zdt.minute(), 16); assert_eq!(zdt.second(), 10); // You can also update a time zone easily. let zurich_zone = TimeZone::try_from_str("Europe/Zurich").unwrap(); let zdt_zurich = zdt.with_timezone(zurich_zone).unwrap(); assert_eq!(zdt_zurich.year(), 2025); assert_eq!(zdt_zurich.month(), 3); assert_eq!(zdt_zurich.day(), 1); assert_eq!(zdt_zurich.hour(), 12); assert_eq!(zdt_zurich.minute(), 16); assert_eq!(zdt_zurich.second(), 10); ``` -------------------------------- ### Create Duration from PartialDuration Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to create a `Duration` object from a `PartialDuration` struct, which allows specifying only certain components. ```rust use temporal_rs::{Duration, PlainDate, partial::PartialDuration}; // Create from partial duration let partial = PartialDuration { hours: Some(3), minutes: Some(45), ..Default::default() }; let duration = Duration::from_partial_duration(partial).unwrap(); assert_eq!(duration.hours(), 3); assert_eq!(duration.minutes(), 45); ``` -------------------------------- ### Date Struct Representation in Boa Source: https://github.com/boa-dev/temporal/blob/main/docs/design/initial-api-concept.md Illustrates how the Date struct is represented in the Boa JavaScript engine, using a generic CalendarProtocol. ```rust struct Date { iso: IsoDate, calendar: CalendarSlot, } ``` -------------------------------- ### Distinguishing Contextual and Non-Contextual Year Fetching Source: https://github.com/boa-dev/temporal/blob/main/docs/design/initial-api-concept.md Proposes an API design to differentiate between fetching a year value with and without explicit context. ```rust let year_1 = Date<()>.year(); ``` ```rust let year_2 = Date<()>.year_with_context(&mut ()); ``` -------------------------------- ### Regenerate Baked Data Source: https://github.com/boa-dev/temporal/blob/main/CONTRIBUTING.md Execute this command to regenerate baked data for the project. ```bash cargo run -p bakeddata ``` -------------------------------- ### Fetching Year Value with Context in Boa Source: https://github.com/boa-dev/temporal/blob/main/docs/design/initial-api-concept.md Demonstrates theoretically fetching a year value from a Date object within the Boa engine, requiring a context argument. ```rust let year_value = Date.year(context); ``` -------------------------------- ### Parse Negative ISO 8601 Duration Source: https://context7.com/boa-dev/temporal/llms.txt Shows how to parse a negative duration specified in ISO 8601 format, represented by a preceding minus sign. ```rust use temporal_rs::Duration; use core::str::FromStr; // Negative duration let negative = Duration::from_str("-P1D").unwrap(); assert_eq!(negative.days(), -1); ``` -------------------------------- ### Fetching Year Value Without Context Source: https://github.com/boa-dev/temporal/blob/main/docs/design/initial-api-concept.md Shows how a user might fetch a year value from a Date object when no custom calendar context is needed. ```rust let year_value = Date<()>.year(&mut ()); ``` -------------------------------- ### Create and Manipulate ZonedDateTime Source: https://context7.com/boa-dev/temporal/llms.txt Use ZonedDateTime for timezone-aware date and time values, handling DST automatically. Requires the `compiled_data` feature for convenience methods. Supports creation from epoch nanoseconds, string parsing with timezone, timezone conversion, duration addition, and formatting. ```rust #[cfg(feature = "compiled_data")] { use temporal_rs::{ZonedDateTime, TimeZone, Calendar, Duration}; use temporal_rs::options::{Disambiguation, DisplayOffset, DisplayTimeZone, DisplayCalendar, ToStringRoundingOptions}; use std::str::FromStr; // Create from epoch nanoseconds let zdt = ZonedDateTime::try_new( 1609459200000000000, // 2021-01-01T00:00:00Z TimeZone::try_from_str("America/New_York").unwrap(), Calendar::default(), ).unwrap(); // Note: Displayed in local timezone (EST = UTC-5) assert_eq!(zdt.year(), 2020); // Dec 31, 2020 in New York assert_eq!(zdt.month(), 12); assert_eq!(zdt.day(), 31); assert_eq!(zdt.hour(), 19); // 7:00 PM EST // Create from string with timezone use temporal_rs::options::{Disambiguation as Dis, OffsetDisambiguation}; let parsed = ZonedDateTime::from_utf8( b"2025-03-01T11:16:10Z[America/Chicago][u-ca=iso8601]", Dis::Compatible, OffsetDisambiguation::Reject ).unwrap(); assert_eq!(parsed.hour(), 5); // UTC projected to Chicago time // Change timezone let zurich_zone = TimeZone::try_from_str("Europe/Zurich").unwrap(); let zdt_zurich = parsed.with_timezone(zurich_zone).unwrap(); assert_eq!(zdt_zurich.hour(), 12); // Same instant, different timezone // Add duration (handles DST automatically) let later = zdt.add(&Duration::from_str("P6M").unwrap(), None).unwrap(); assert_eq!(later.month(), 7); // July // Format to RFC 9557 IXDTF string let iso_string = zdt.to_ixdtf_string( DisplayOffset::Auto, DisplayTimeZone::Auto, DisplayCalendar::Auto, ToStringRoundingOptions::default() ).unwrap(); // Results in: "2020-12-31T19:00:00-05:00[America/New_York]" assert!(iso_string.contains("[America/New_York]")); } ``` -------------------------------- ### Debug Single test262 Test with Verbose Output Source: https://github.com/boa-dev/temporal/blob/main/docs/testing.md Debug a specific test262 test by running it in verbose mode (-vvv) with boa_tester. This displays detailed output, including failure reasons. ```bash cargo run --bin boa_tester -- run -vvv --console -s test/built-ins/Temporal/Instant/compare/argument-string-limits.js ``` -------------------------------- ### Parse Time-Only ISO 8601 Duration Source: https://context7.com/boa-dev/temporal/llms.txt Illustrates parsing an ISO 8601 duration string that only contains time components (hours and minutes). ```rust use temporal_rs::Duration; use core::str::FromStr; // Time-only duration let movie_length = Duration::from_str("PT2H30M").unwrap(); assert_eq!(movie_length.hours(), 2); assert_eq!(movie_length.minutes(), 30); ``` -------------------------------- ### Parse and Manipulate PlainDateTime Source: https://context7.com/boa-dev/temporal/llms.txt Use PlainDateTime for combined date and time values without timezone information. Supports parsing ISO 8601 strings, date arithmetic, and component extraction. ```rust use temporal_rs::{PlainDateTime, Duration, fields::DateTimeFields, partial::PartialTime}; use core::str::FromStr; // Parse ISO 8601 datetime string let dt = PlainDateTime::from_str("2024-03-15T14:30:45.123456789").unwrap(); assert_eq!(dt.year(), 2024); assert_eq!(dt.month(), 3); assert_eq!(dt.day(), 15); assert_eq!(dt.hour(), 14); assert_eq!(dt.minute(), 30); // DateTime arithmetic - add 1 month, 2 days, 3 hours, 4 minutes let start = PlainDateTime::from_str("2024-01-15T12:00:00").unwrap(); let later = start.add(&Duration::from_str("P1M2DT3H4M").unwrap(), None).unwrap(); assert_eq!(later.month(), 2); assert_eq!(later.day(), 17); assert_eq!(later.hour(), 15); assert_eq!(later.minute(), 4); // Calculate difference between datetimes let earlier = PlainDateTime::from_str("2024-01-10T10:30:00").unwrap(); let duration = earlier.until(&start, Default::default()).unwrap(); assert_eq!(duration.days(), 5); assert_eq!(duration.hours(), 1); assert_eq!(duration.minutes(), 30); // Extract date and time components let date = dt.to_plain_date(); assert_eq!(date.year(), 2024); let time = dt.to_plain_time(); assert_eq!(time.hour(), 14); // Modify specific fields let fields = DateTimeFields::new() .with_partial_time(PartialTime::new().with_hour(Some(18))); let modified = dt.with(fields, None).unwrap(); assert_eq!(modified.hour(), 18); assert_eq!(modified.minute(), 30); // unchanged ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.