### Install Rebase Tools Dependencies Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Navigate to the 'tools' directory and install the necessary Node.js dependencies for the rebase tooling using npm ci. ```shell cd tools && npm ci && cd .. ``` -------------------------------- ### Start the rebase process Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Initiate the rebase using the trt tool with the specified upstream commits. ```bash trt $LATEST_UPSTREAMED_COMMIT $TARGET_UPSTREAM_COMMIT --onto pub/main ``` -------------------------------- ### Install Temporal Polyfill Source: https://github.com/js-temporal/temporal-polyfill/blob/main/README.md Use npm to add the polyfill package to your project dependencies. ```bash $ npm install @js-temporal/polyfill ``` -------------------------------- ### Example test script for rebase automation Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md A sample shell script to validate builds, linting, and tests during the rebase process. ```sh #!/bin/bash set -e npm run build npm run lint npm run test npm run test262 ``` -------------------------------- ### Check Rebase Tool Execution Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Verify that the rebase-upstream-commits TypeScript script can be executed using npx ts-node. This command should display the tool's command-line help if installed correctly. ```shell npx ts-node tools/rebase-upstream-commits.ts ``` -------------------------------- ### String Representation of Temporal.Duration Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates how to get the ISO 8601 string representation of a Temporal.Duration object using `toString` and `toJSON`. ```javascript // Output console.log(dur1.toString()); // "P1Y2M3DT4H5M6S" console.log(dur1.toJSON()); // "P1Y2M3DT4H5M6S" ``` -------------------------------- ### Get Total Units of Temporal.Duration Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Explains how to calculate the total duration in a specific unit using the `total` method. The `relativeTo` option is necessary when the duration includes calendar units like years or months. ```javascript // Get total in specific unit const totalDays = dur1.total({ unit: 'day', relativeTo: '2024-01-01' }); console.log(totalDays); // approximately 428.17 const totalHours = Temporal.Duration.from('PT2H30M').total('hour'); console.log(totalHours); // 2.5 ``` -------------------------------- ### Modify, Negate, and Absolute Value of Temporal.Duration Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to create a new duration with modified components using the `with` method, negate an existing duration using `negated`, and get the absolute value of a duration using `abs`. ```javascript // Modify duration const modified = dur1.with({ hours: 10 }); // Negate and absolute value const negated = dur1.negated(); const absolute = negated.abs(); ``` -------------------------------- ### Import and Initialize Temporal Polyfill Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates how to import the polyfill using ESM or CJS and optionally extend the Date prototype. ```javascript // ESM import import { Temporal, Intl, toTemporalInstant } from '@js-temporal/polyfill'; // CJS require const { Temporal, Intl, toTemporalInstant } = require('@js-temporal/polyfill'); // Optionally extend Date prototype for easy conversion Date.prototype.toTemporalInstant = toTemporalInstant; // Now you can use Temporal types const now = Temporal.Now.instant(); console.log(now.toString()); // "2024-01-15T10:30:00Z" ``` -------------------------------- ### Create and Access Temporal.PlainDateTime Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creating Temporal.PlainDateTime instances using from() and the constructor, and accessing its various properties. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create PlainDateTime const dt1 = Temporal.PlainDateTime.from('2024-01-15T10:30:00'); const dt2 = Temporal.PlainDateTime.from({ year: 2024, month: 1, day: 15, hour: 10, minute: 30, second: 0 }); const dt3 = new Temporal.PlainDateTime(2024, 1, 15, 10, 30, 0); // Access all properties console.log(dt1.year, dt1.month, dt1.day); // 2024 1 15 console.log(dt1.hour, dt1.minute, dt1.second); // 10 30 0 console.log(dt1.dayOfWeek); // 1 (Monday) console.log(dt1.dayOfYear); // 15 console.log(dt1.weekOfYear); // 3 ``` -------------------------------- ### Create and Access Temporal.PlainMonthDay Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to create Temporal.PlainMonthDay instances using from() and the constructor, and access its monthCode and day properties. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create month-day const md1 = Temporal.PlainMonthDay.from('--01-15'); const md2 = Temporal.PlainMonthDay.from({ month: 1, day: 15 }); const md3 = new Temporal.PlainMonthDay(1, 15); // Access properties console.log(md1.monthCode); // "M01" console.log(md1.day); // 15 ``` -------------------------------- ### Create Instant from Epoch Units Source: https://github.com/js-temporal/temporal-polyfill/blob/main/CHANGELOG.md Replaces removed static factory methods with alternatives using milliseconds or nanoseconds. ```javascript Temporal.Instant.fromEpochMilliseconds(epochSeconds * 1000) ``` ```javascript Temporal.Instant.fromEpochNanoseconds(epochMicroseconds * 1000) ``` -------------------------------- ### Create and Access Temporal.PlainYearMonth Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to create Temporal.PlainYearMonth instances using from() and the constructor, and access its properties like year, month, and days in month. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create year-month const ym1 = Temporal.PlainYearMonth.from('2024-01'); const ym2 = Temporal.PlainYearMonth.from({ year: 2024, month: 1 }); const ym3 = new Temporal.PlainYearMonth(2024, 1); // Access properties console.log(ym1.year); // 2024 console.log(ym1.month); // 1 console.log(ym1.monthCode); // "M01" console.log(ym1.daysInMonth); // 31 console.log(ym1.daysInYear); // 366 console.log(ym1.monthsInYear); // 12 console.log(ym1.inLeapYear); // true ``` -------------------------------- ### Create and Access Temporal.Duration Components Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creating Temporal.Duration objects using different methods and accessing their individual components like years, months, days, hours, etc. Also shows how to check the sign and blank status of a duration. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create durations const dur1 = Temporal.Duration.from('P1Y2M3DT4H5M6S'); const dur2 = Temporal.Duration.from({ years: 1, months: 2, days: 3, hours: 4 }); const dur3 = new Temporal.Duration(1, 2, 0, 3, 4, 5, 6, 0, 0, 0); // Access components console.log(dur1.years); // 1 console.log(dur1.months); // 2 console.log(dur1.weeks); // 0 console.log(dur1.days); // 3 console.log(dur1.hours); // 4 console.log(dur1.minutes); // 5 console.log(dur1.seconds); // 6 console.log(dur1.milliseconds); // 0 console.log(dur1.microseconds); // 0 console.log(dur1.nanoseconds); // 0 // Sign and blank console.log(dur1.sign); // 1 (positive), -1 (negative), or 0 (zero) console.log(dur1.blank); // false (true if zero duration) ``` -------------------------------- ### Manage Exact Time Points with Temporal.Instant Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Covers creation, arithmetic, comparison, and conversion of exact moments in time. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create from various sources const instant1 = Temporal.Instant.from('2024-01-15T10:30:00Z'); const instant2 = Temporal.Instant.fromEpochMilliseconds(1705315800000); const instant3 = Temporal.Instant.fromEpochNanoseconds(1705315800000000000n); const instant4 = new Temporal.Instant(1705315800000000000n); // Access epoch values console.log(instant1.epochMilliseconds); // 1705315800000 console.log(instant1.epochNanoseconds); // 1705315800000000000n // Add/subtract durations (only time units allowed) const later = instant1.add({ hours: 2, minutes: 30 }); const earlier = instant1.subtract({ seconds: 45 }); // Calculate difference between instants const duration = instant1.until(later, { largestUnit: 'hour' }); console.log(duration.toString()); // "PT2H30M" const sinceDuration = later.since(instant1); console.log(sinceDuration.toString()); // "PT2H30M" // Round to specific precision const rounded = instant1.round({ smallestUnit: 'minute', roundingMode: 'halfExpand' }); // Compare instants console.log(Temporal.Instant.compare(instant1, later)); // -1 // Convert to timezone-aware ZonedDateTime const zdt = instant1.toZonedDateTimeISO('America/New_York'); console.log(zdt.toString()); // "2024-01-15T05:30:00-05:00[America/New_York]" // Equality check console.log(instant1.equals(instant2)); // true // String representations console.log(instant1.toString()); // "2024-01-15T10:30:00Z" console.log(instant1.toString({ timeZone: 'Europe/Paris' })); // "2024-01-15T11:30:00+01:00" console.log(instant1.toJSON()); // "2024-01-15T10:30:00Z" ``` -------------------------------- ### Manipulating Dates with Calendars Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creating dates in specific calendars, accessing calendar-specific properties, converting between systems, and performing arithmetic. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create dates with different calendars const isoDate = Temporal.PlainDate.from('2024-01-15'); const hebrewDate = Temporal.PlainDate.from({ year: 5784, month: 4, day: 5, calendar: 'hebrew' }); const japaneseDate = isoDate.withCalendar('japanese'); // Access calendar-specific properties console.log(japaneseDate.era); // "reiwa" console.log(japaneseDate.eraYear); // 6 console.log(japaneseDate.year); // 2024 // Convert between calendars const converted = hebrewDate.withCalendar('iso8601'); console.log(converted.toString()); // ISO date equivalent // Calendar-aware arithmetic const nextMonth = hebrewDate.add({ months: 1 }); console.log(nextMonth.toString({ calendarName: 'always' })); // Supported calendars: iso8601, hebrew, islamic, islamic-civil, islamic-umalqura, // indian, buddhist, chinese, coptic, dangi, ethioaa, ethiopic, gregory, japanese, // persian, roc ``` -------------------------------- ### Convert and Compare Temporal.PlainDateTime Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates converting a Temporal.PlainDateTime to other Temporal types like PlainDate, PlainTime, and ZonedDateTime, and comparing instances for equality and order. ```javascript // Convert to other types const plainDate = dt1.toPlainDate(); const plainTime = dt1.toPlainTime(); const zonedDateTime = dt1.toZonedDateTime('America/New_York', { disambiguation: 'compatible' }); // Compare and equality console.log(Temporal.PlainDateTime.compare(dt1, later)); // -1 console.log(dt1.equals(dt2)); // true // Output console.log(dt1.toString()); // "2024-01-15T10:30:00" ``` -------------------------------- ### Initialize Test262 Submodule Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Update the test262 submodule if it hasn't been initialized or updated previously. This ensures the test suite is available. ```shell git submodule update ``` -------------------------------- ### Temporal.PlainTime Usage Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creating, modifying, rounding, and performing arithmetic on wall-clock times without date or timezone information. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create times const time1 = Temporal.PlainTime.from('10:30:00'); const time2 = Temporal.PlainTime.from({ hour: 10, minute: 30, second: 0 }); const time3 = new Temporal.PlainTime(10, 30, 0, 0, 0, 0); // With sub-second precision const precise = Temporal.PlainTime.from('14:30:45.123456789'); // Access components console.log(time1.hour); // 10 console.log(time1.minute); // 30 console.log(time1.second); // 0 console.log(time1.millisecond); // 0 console.log(time1.microsecond); // 0 console.log(time1.nanosecond); // 0 // Modify time const modified = time1.with({ hour: 14, minute: 0 }); // Time arithmetic (wraps at midnight) const later = time1.add({ hours: 2, minutes: 45 }); const earlier = time1.subtract({ minutes: 30 }); // Calculate differences const diff = time1.until('12:00:00', { largestUnit: 'hour' }); console.log(diff.toString()); // "PT1H30M" // Round to specific precision const rounded = precise.round('second'); const roundedTo5Min = time1.round({ smallestUnit: 'minute', roundingIncrement: 5 }); // Compare times console.log(Temporal.PlainTime.compare(time1, later)); // -1 console.log(time1.equals('10:30')); // true // Output console.log(time1.toString()); // "10:30:00" console.log(precise.toString({ smallestUnit: 'millisecond' })); // "14:30:45.123" ``` -------------------------------- ### Format Temporal Objects with Intl.DateTimeFormat Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Illustrates using the polyfill's extension of `Intl.DateTimeFormat` to format various Temporal objects like PlainDate, PlainTime, PlainDateTime, Instant, and ZonedDateTime. Requires importing `Intl` from the polyfill. ```javascript import { Temporal, Intl } from '@js-temporal/polyfill'; const date = Temporal.PlainDate.from('2024-01-15'); const time = Temporal.PlainTime.from('14:30:00'); const dateTime = Temporal.PlainDateTime.from('2024-01-15T14:30:00'); const instant = Temporal.Instant.from('2024-01-15T14:30:00Z'); const zonedDateTime = Temporal.ZonedDateTime.from('2024-01-15T14:30:00[America/New_York]'); // Format using Intl.DateTimeFormat const dateFormatter = new Intl.DateTimeFormat('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); console.log(dateFormatter.format(date)); // "Monday, January 15, 2024" const timeFormatter = new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }); console.log(timeFormatter.format(time)); // "2:30 PM" // Format with timezone display const fullFormatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'long', timeZone: 'America/New_York' }); console.log(fullFormatter.format(instant)); // "Monday, January 15, 2024 at 9:30:00 AM EST" // Format range const date2 = Temporal.PlainDate.from('2024-01-20'); console.log(dateFormatter.formatRange(date, date2)); // "January 15 – 20, 2024" // Using toLocaleString directly console.log(date.toLocaleString('fr-FR', { dateStyle: 'long' })); // "15 janvier 2024" console.log(time.toLocaleString('de-DE', { timeStyle: 'short' })); // "14:30" console.log(instant.toLocaleString('ja-JP', { dateStyle: 'short', timeStyle: 'short' })); ``` -------------------------------- ### Compare Temporal.Duration Objects Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to compare two durations using `Temporal.Duration.compare`. The `relativeTo` option is required for accurate comparison when calendar units are involved. ```javascript // Compare durations (requires relativeTo for calendar units) console.log(Temporal.Duration.compare( { days: 30 }, { months: 1 }, { relativeTo: '2024-01-01' } )); // 1 (30 days > January's 31 days expressed as "1 month") ``` -------------------------------- ### Convert Legacy Date to Temporal.Instant Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to convert a JavaScript `Date` object to a `Temporal.Instant` using the `toTemporalInstant` function, either by extending the `Date.prototype` or by calling the function directly. ```javascript import { Temporal, toTemporalInstant } from '@js-temporal/polyfill'; // Extend Date prototype (optional, do once at app startup) Date.prototype.toTemporalInstant = toTemporalInstant; // Convert a Date to Temporal.Instant const legacyDate = new Date('2024-01-15T10:30:00Z'); const instant = legacyDate.toTemporalInstant(); console.log(instant.toString()); // "2024-01-15T10:30:00Z" // Then convert to other types as needed const zonedDateTime = instant.toZonedDateTimeISO('America/New_York'); console.log(zonedDateTime.toString()); // "2024-01-15T05:30:00-05:00[America/New_York]" // Without extending prototype const instant2 = toTemporalInstant.call(new Date()); console.log(instant2.epochMilliseconds); ``` -------------------------------- ### Fetch Updates from Remotes Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Fetch the latest changes from both the 'pub' (your fork) and 'spec-pub' (upstream specification) remotes to ensure your local repository has the most recent data. ```shell git fetch pub && git fetch spec-pub ``` -------------------------------- ### Add 'pub' Git Remote Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Add the js-temporal/temporal-polyfill repository as a git remote named 'pub'. This is used for managing your local fork's main branch. ```shell git remote add pub git@github.com:js-temporal/temporal-polyfill.git ``` -------------------------------- ### Calculate Differences and Convert Temporal.PlainYearMonth Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Illustrates calculating the difference between two Temporal.PlainYearMonth instances using until() and converting to a PlainDate for the first or last day of the month. ```javascript // Calculate differences const diff = ym1.until('2024-12', { largestUnit: 'month' }); console.log(diff.months); // 11 // Convert to PlainDate const firstOfMonth = ym1.toPlainDate({ day: 1 }); const lastOfMonth = ym1.toPlainDate({ day: ym1.daysInMonth }); // Compare console.log(Temporal.PlainYearMonth.compare(ym1, nextMonth)); // -1 console.log(ym1.equals('2024-01')); // true console.log(ym1.toString()); // "2024-01" ``` -------------------------------- ### Create a fixup commit Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Create a fixup commit to address issues in a specific previous commit during code review. ```bash git commit --fixup ``` -------------------------------- ### Modify and Perform Arithmetic on Temporal.PlainYearMonth Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates modifying a Temporal.PlainYearMonth using with() and performing arithmetic operations like add() and subtract() for months and years. ```javascript // Modify const modified = ym1.with({ month: 6 }); // Arithmetic const nextMonth = ym1.add({ months: 1 }); const lastYear = ym1.subtract({ years: 1 }); ``` -------------------------------- ### Rounding and Balancing Temporal.Duration Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates how to round a duration to a specific smallest and largest unit using the `round` method. The `relativeTo` option is crucial for calculations involving calendar units like years and months. ```javascript // Round duration (requires relativeTo for calendar units) const rounded = dur1.round({ smallestUnit: 'day', largestUnit: 'year', relativeTo: '2024-01-01' }); // Balance to different units const balanced = dur1.round({ largestUnit: 'hour', relativeTo: '2024-01-01' }); ``` -------------------------------- ### Import Temporal Polyfill Source: https://github.com/js-temporal/temporal-polyfill/blob/main/README.md Integrate the polyfill into your project using either CommonJS or ES6 module syntax. Note that the polyfill does not attach to the global object by default. ```javascript const { Temporal, Intl, toTemporalInstant } = require('@js-temporal/polyfill'); Date.prototype.toTemporalInstant = toTemporalInstant; ``` ```javascript import { Temporal, Intl, toTemporalInstant } from '@js-temporal/polyfill'; Date.prototype.toTemporalInstant = toTemporalInstant; ``` -------------------------------- ### Create Alias for Rebase Tool Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Create a shell alias 'trt' for the command that runs the rebase-upstream-commits script with the 'realcmd' argument. This simplifies repeated execution of the tool. ```shell alias trt="$(npx ts-node tools/rebase-upstream-commits.ts realcmd)" ``` -------------------------------- ### Temporal.ZonedDateTime Usage Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creation, component access, arithmetic, and conversion methods for timezone-aware dates. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create from ISO string with timezone annotation const zdt1 = Temporal.ZonedDateTime.from('2024-01-15T10:30:00[America/New_York]'); const zdt2 = Temporal.ZonedDateTime.from({ year: 2024, month: 1, day: 15, hour: 10, minute: 30, timeZone: 'Europe/London' }); // Create with explicit epoch nanoseconds const zdt3 = new Temporal.ZonedDateTime(1705315800000000000n, 'America/Los_Angeles'); // Access all date/time components console.log(zdt1.year); // 2024 console.log(zdt1.month); // 1 console.log(zdt1.day); // 15 console.log(zdt1.hour); // 10 console.log(zdt1.minute); // 30 console.log(zdt1.second); // 0 console.log(zdt1.dayOfWeek); // 1 (Monday) console.log(zdt1.dayOfYear); // 15 console.log(zdt1.weekOfYear); // 3 console.log(zdt1.daysInMonth); // 31 console.log(zdt1.inLeapYear); // true // Timezone information console.log(zdt1.timeZoneId); // "America/New_York" console.log(zdt1.offset); // "-05:00" console.log(zdt1.offsetNanoseconds); // -18000000000000 console.log(zdt1.hoursInDay); // 24 (or 23/25 during DST transitions) // Epoch values console.log(zdt1.epochMilliseconds); // timestamp in ms console.log(zdt1.epochNanoseconds); // timestamp in ns (bigint) // Modify components immutably const modified = zdt1.with({ hour: 14, minute: 0 }); const withNewTime = zdt1.withPlainTime('14:00'); const withNewTimezone = zdt1.withTimeZone('Asia/Tokyo'); const withNewCalendar = zdt1.withCalendar('japanese'); // Arithmetic with DST awareness const nextWeek = zdt1.add({ weeks: 1 }); const yesterday = zdt1.subtract({ days: 1 }); const inThreeMonths = zdt1.add({ months: 3 }); // Calculate differences const diff = zdt1.until(nextWeek, { largestUnit: 'day' }); console.log(diff.toString()); // "P7D" // Get start of day (handles DST correctly) const startOfDay = zdt1.startOfDay(); // Round to specific precision const roundedToHour = zdt1.round('hour'); const roundedTo15Min = zdt1.round({ smallestUnit: 'minute', roundingIncrement: 15 }); // Find timezone transitions (DST changes) const nextTransition = zdt1.getTimeZoneTransition('next'); const prevTransition = zdt1.getTimeZoneTransition('previous'); // Convert to other Temporal types const instant = zdt1.toInstant(); const plainDate = zdt1.toPlainDate(); const plainTime = zdt1.toPlainTime(); const plainDateTime = zdt1.toPlainDateTime(); // Comparison and equality console.log(Temporal.ZonedDateTime.compare(zdt1, zdt2)); // -1, 0, or 1 console.log(zdt1.equals(zdt2)); // false // String output console.log(zdt1.toString()); // "2024-01-15T10:30:00-05:00[America/New_York]" console.log(zdt1.toJSON()); // same as toString() ``` -------------------------------- ### Calculate Differences and Round Temporal.PlainDateTime Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Illustrates calculating the difference between two Temporal.PlainDateTime objects using until() and rounding to a specific precision using round(). ```javascript // Calculate differences const diff = dt1.until(later, { largestUnit: 'day' }); console.log(diff.toString()); // "P5DT3H" // Round to precision const rounded = dt1.round('hour'); const roundedTo15Min = dt1.round({ smallestUnit: 'minute', roundingIncrement: 15 }); ``` -------------------------------- ### View Git Log Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Display the git log, showing the current commit history. This is useful for verifying branch alignment and identifying specific commits. ```shell git log ``` -------------------------------- ### Temporal.PlainDate Usage Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates creating, modifying, performing arithmetic, and converting calendar dates without time or timezone information. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Create dates const date1 = Temporal.PlainDate.from('2024-01-15'); const date2 = Temporal.PlainDate.from({ year: 2024, month: 1, day: 15 }); const date3 = new Temporal.PlainDate(2024, 1, 15); // With non-ISO calendar const hebrewDate = Temporal.PlainDate.from({ year: 5784, month: 4, day: 5, calendar: 'hebrew' }); // Access properties console.log(date1.year); // 2024 console.log(date1.month); // 1 console.log(date1.monthCode); // "M01" console.log(date1.day); // 15 console.log(date1.dayOfWeek); // 1 (Monday) console.log(date1.dayOfYear); // 15 console.log(date1.weekOfYear); // 3 console.log(date1.daysInMonth); // 31 console.log(date1.daysInYear); // 366 console.log(date1.monthsInYear); // 12 console.log(date1.inLeapYear); // true console.log(date1.calendarId); // "iso8601" // Modify dates const modified = date1.with({ month: 6, day: 1 }); const withCalendar = date1.withCalendar('japanese'); // Date arithmetic const nextMonth = date1.add({ months: 1 }); const lastWeek = date1.subtract({ weeks: 1 }); const farFuture = date1.add({ years: 5, months: 3, days: 10 }); // Calculate differences const diff = date1.until(nextMonth, { largestUnit: 'month' }); console.log(diff.toString()); // "P1M" const daysSince = date1.since('2024-01-01', { largestUnit: 'day' }); console.log(daysSince.days); // 14 // Compare dates console.log(Temporal.PlainDate.compare(date1, nextMonth)); // -1 console.log(date1.equals('2024-01-15')); // true // Convert to other types const dateTime = date1.toPlainDateTime('10:30:00'); const zonedDateTime = date1.toZonedDateTime({ timeZone: 'America/New_York', plainTime: '09:00' }); const yearMonth = date1.toPlainYearMonth(); const monthDay = date1.toPlainMonthDay(); // Formatting console.log(date1.toString()); // "2024-01-15" console.log(date1.toLocaleString('en-US', { dateStyle: 'full' })); // "Monday, January 15, 2024" ``` -------------------------------- ### Temporal.Duration Arithmetic Operations Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Illustrates performing addition and subtraction operations on Temporal.Duration objects. Note that calendar units like months require a `relativeTo` option for accurate calculations. ```javascript // Arithmetic const sum = dur1.add({ days: 7, hours: 2 }); const difference = dur1.subtract({ months: 1 }); ``` -------------------------------- ### Modify and Convert Temporal.PlainMonthDay Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Demonstrates modifying a Temporal.PlainMonthDay using with() and converting it to a PlainDate for a specific year. ```javascript // Modify const modified = md1.with({ day: 20 }); // Convert to PlainDate for a specific year const date2024 = md1.toPlainDate({ year: 2024 }); const date2025 = md1.toPlainDate({ year: 2025 }); // Equality check console.log(md1.equals('--01-15')); // true console.log(md1.toString()); // "--01-15" ``` -------------------------------- ### Run tests after rebase changes Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Execute the test script automatically after each substantial change during the rebase. ```bash --exec=./test.sh ``` -------------------------------- ### Update Local 'main' Branch Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Ensure your local 'main' branch is up-to-date with the 'main' branch of your 'pub' remote using a fast-forward merge. This synchronizes your local work with your fork's latest state. ```shell git checkout main && git merge --ff-only pub/main ``` -------------------------------- ### Add 'spec-pub' Git Remote Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Add the upstream Temporal proposal repository as a git remote named 'spec-pub'. This remote is necessary for fetching the latest specification changes. ```shell git remote add spec-pub https://github.com/tc39/proposal-temporal.git ``` -------------------------------- ### Modify and Perform Arithmetic on Temporal.PlainDateTime Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Shows how to modify components of a Temporal.PlainDateTime object using with() and perform date/time arithmetic using add() and subtract(). ```javascript // Modify components const modified = dt1.with({ hour: 14, day: 20 }); const withNewTime = dt1.withPlainTime('15:45:30'); const withCalendar = dt1.withCalendar('japanese'); // Arithmetic const later = dt1.add({ days: 5, hours: 3 }); const earlier = dt1.subtract({ months: 1, minutes: 30 }); ``` -------------------------------- ### Save work after finishing rebase Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Create a new branch from the detached HEAD state after running trt finish. ```bash git checkout -b ``` -------------------------------- ### Rebase Branch with Autosquash Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Use this command to rebase your branch interactively with autosquash. After running, save and quit the editor without changes to squash fixup commits while preserving the overall history. ```git git rebase -i main --autosquash ``` -------------------------------- ### View upstream file diffs Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Display file diffs from an upstream change with a specified number of unified diff lines. ```bash trt basediff -U40 -- polyfill/lib/ecmascript.mjs ``` -------------------------------- ### Calculate Epoch Seconds and Microseconds Source: https://github.com/js-temporal/temporal-polyfill/blob/main/CHANGELOG.md Replaces removed epoch properties with manual calculations using epochMilliseconds or epochNanoseconds. ```javascript Math.floor(epochMilliseconds / 1000) ``` ```javascript epochNanoseconds / 1000n + ((epochNanoseconds % 1000n) < 0n ? -1n : 0n) ``` -------------------------------- ### Export target commit variable Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Set the target commit hash as an environment variable for easier command reference. ```bash export TARGET_UPSTREAM_COMMIT= ``` -------------------------------- ### List outstanding commits to rebase Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Command to identify commits between the latest upstreamed commit and the current main branch. ```bash git log $LATEST_UPSTREAMED_COMMIT..spec-pub/main --oneline -- ./polyfill/ ``` -------------------------------- ### Export Latest Upstreamed Commit Hash Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Export the identified latest upstream commit hash to an environment variable for easy reference in subsequent commands. Replace `` with the actual commit hash. ```shell export LATEST_UPSTREAMED_COMMIT= ``` -------------------------------- ### Retrieve Current Time with Temporal.Now Source: https://context7.com/js-temporal/temporal-polyfill/llms.txt Provides methods to access the current date, time, or timezone identifier. ```javascript import { Temporal } from '@js-temporal/polyfill'; // Get current instant (exact point in time) const instant = Temporal.Now.instant(); console.log(instant.epochMilliseconds); // 1705315800000 // Get current date and time in a specific timezone const zonedDateTime = Temporal.Now.zonedDateTimeISO('America/New_York'); console.log(zonedDateTime.toString()); // "2024-01-15T05:30:00-05:00[America/New_York]" // Get current date in a timezone (no time component) const plainDate = Temporal.Now.plainDateISO('Europe/London'); console.log(plainDate.toString()); // "2024-01-15" // Get current time in a timezone (no date component) const plainTime = Temporal.Now.plainTimeISO('Asia/Tokyo'); console.log(plainTime.toString()); // "19:30:00" // Get current date and time (no timezone retained) const plainDateTime = Temporal.Now.plainDateTimeISO(); console.log(plainDateTime.toString()); // "2024-01-15T10:30:00" // Get the system's current timezone identifier const timeZoneId = Temporal.Now.timeZoneId(); console.log(timeZoneId); // "America/Los_Angeles" ``` -------------------------------- ### Enforce throwing behavior for date overflow Source: https://github.com/js-temporal/temporal-polyfill/blob/main/CHANGELOG.md Use the reject overflow option to ensure that invalid date components throw an error instead of clamping. ```javascript const { monthCode, day } = birthday; Temporal.PlainDate.from({ year: 2025, monthCode, day }, { overflow: 'reject' }); ``` -------------------------------- ### Update expected failure files Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Automatically remove tests from expected-failure files if they are now passing. ```bash npm run test262 -- --update-expected-failure-files ``` -------------------------------- ### Find Latest Upstreamed Commit Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Search the git log of the 'pub/main' branch for commits that have 'UPSTREAM_COMMIT=' in their description. This helps identify the hash of the most recent upstream commit that was successfully migrated. ```shell git log --grep 'UPSTREAM_COMMIT=' pub/main ``` -------------------------------- ### Rebase Type-Checking Pattern for Function Parameters Source: https://github.com/js-temporal/temporal-polyfill/blob/main/tools/rebasing.md Use this pattern to handle TypeScript type narrowing when re-assigning function parameters by renaming the parameter and creating a local variable. ```js // Code upstream static compare(one, two) { one = ES.ToTemporalDate(one); ``` ```ts static compare(oneParam: Params['compare'][0], twoParam: Params['compare'][1]): Return['compare'] { // We rename the function parameter and re-use the old name so the variable's type is correctly narrowed as a result of calling `ToTemporalDate` const one = ES.ToTemporalDate(oneParam); ``` -------------------------------- ### Parse UTC Time Portion Source: https://github.com/js-temporal/temporal-polyfill/blob/main/CHANGELOG.md Use this pattern to correctly extract the time portion from a UTC timestamp string while avoiding common local time interpretation bugs. ```javascript Temporal.Instant.from(s).toZonedDateTimeISO('UTC').toPlainTime() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.