### Install temporal-polyfill-lite Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md Install the package using npm. This is the first step to using the polyfill in your project. ```sh npm install temporal-polyfill-lite ``` -------------------------------- ### Manually Install Polyfill Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md Use the `install` function from the shim module to manually apply the polyfill. You can choose whether to overwrite the native Temporal implementation. ```typescript // or you can manually install the polyfill import { install } from "temporal-polyfill-lite/shim"; // overwrite native Temporal implementation install(true); // don't overwrite native Temporal implementation install(false); ``` -------------------------------- ### Formatting Time Ranges Across Midnight in Older Browsers Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/docs/restrictions.md Formatting time ranges that cross or end at midnight is not supported in browsers and runtimes released before 2022. This example demonstrates a `formatRange` call that would result in a `RangeError` in older environments. ```javascript new Intl.DateTimeFormat("en-US").formatRange( Temporal.PlainTime.from("23:00"), Temporal.PlainTime.from("00:00"), ); // "11:00:00 PM – 12:00:00 AM", but `RangeError` in older browsers ``` -------------------------------- ### Formatting Dates Near Boundaries Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/docs/restrictions.md This polyfill has limitations in formatting `PlainDate`, `PlainDateTime`, and `PlainYearMonth` objects near their lower bounds, and `PlainDateTime` near its upper bound. Native implementations may not exhibit this behavior. The example shows cases that will throw an error in this polyfill. ```javascript // This polyfill will throw for these cases (but native implementations not): Temporal.PlainDate.from("-271821-04-19").toLocaleString("en-US"); Temporal.PlainDateTime.from("-271821-04-19T00:00:01").toLocaleString("en-US"); Temporal.PlainYearMonth.from("-271821-04-19[u-ca=gregory]").toLocaleString("en-US"); Temporal.PlainDateTime.from("+275760-09-13T23:59:59").toLocaleString("en-US"); ``` -------------------------------- ### Time Zone Equivalence in Safari/JavaScriptCore Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/docs/restrictions.md Safari's JavaScriptCore does not resolve linked time zones from the `backward` file, leading to potential inaccuracies in `Temporal.ZonedDateTime.prototype.equals` for renamed or merged time zone IDs. This example shows a case where equivalence is incorrectly reported as false. ```javascript new Temporal.ZonedDateTime(0n, "Europe/Kiev").equals(new Temporal.ZonedDateTime(0n, "Europe/Kyiv")); // correct: `true` (Chrome, Firefox, Node.js) // incorrect: `false` (Safari, Bun) ``` -------------------------------- ### Import Full Calendar Bundle Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md If you need calendars other than Gregorian (e.g., Hebrew, Chinese, Indian), import the 'calendars-full' bundle instead of the default. ```typescript import { Intl, Temporal } from "temporal-polyfill-lite/calendars-full"; import "temporal-polyfill-lite/calendars-full/global"; import { install } from "temporal-polyfill-lite/calendars-full/shim"; ``` -------------------------------- ### Basic Ponyfill Usage Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md Import Temporal and Intl as a ponyfill to avoid patching global variables. This is useful for isolated usage. ```typescript // as a ponyfill (without patching global variables) import { Intl, Temporal } from "temporal-polyfill-lite"; ``` -------------------------------- ### Enable System Time Zone ID Caching Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md Configure an opt-in cache for `Temporal.Now.timeZoneId` to improve performance. Set the Time To Live (TTL) in milliseconds. ```typescript import { setSystemTimeZoneIdCacheTtl } from "temporal-polyfill-lite/shim"; // or use "temporal-polyfill-lite/calendars-full/shim" entrypoint if you use the "full" bundle setSystemTimeZoneIdCacheTtl(1000); // The result of `Temporal.Now.timeZoneId()` will be cached for a second ``` -------------------------------- ### Load Polyfill to Global Scope Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/README.md Import the global module to patch the global Temporal object. This makes the polyfill available everywhere. ```typescript // load the polyfill to global import "temporal-polyfill-lite/global"; // load types to global if you need (optional) import "temporal-polyfill-lite/types/global"; ``` -------------------------------- ### Other Intl.DateTimeFormat Issues Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/docs/restrictions.md The polyfill integrates Temporal support into `Intl.DateTimeFormat` without altering its core logic. Consequently, any existing bugs or spec deviations in the native environment's `Intl.DateTimeFormat` implementation will persist. ```javascript // No specific code example provided for this general limitation. ``` -------------------------------- ### Precision Issues in Temporal.Duration.prototype.total Source: https://github.com/fabon-f/temporal-polyfill-lite/blob/master/docs/restrictions.md Floating-point precision errors can occur when using units of 'minutes' or larger with `Temporal.Duration.prototype.total`. This snippet demonstrates the potential discrepancy between the expected and polyfill output. ```javascript Temporal.Duration.from("PT816H2049.18749766S").total("hours"); // spec: 816.56921874935 // polyfill: 816.5692187493501 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.