Commit Graph
20 Commits
Author SHA1 Message Date
David Richardson 6f1f56205e Refactor CPTimeZone to use dynamic Intl validation and host-native IANA enumeration
* Fully remove the static, hand-maintained knownTimeZoneNames array and knownTimeZoneNamesSet dictionary from +initialize.

* Implement runtime dynamic population via Intl.supportedValuesOf("timeZone") with strict fallback handling for GMT and UTC.

* Introduce a robust _isValidTimeZoneName runtime check utilizing Intl.DateTimeFormat validation to reject unrecognized zone names dynamically rather than relying on a stale static list.
 * Update initWithName: and _initWithName:abbreviation: to leverage the new engine-native validation bridge.
2026-09-11 18:53:33 -06:00
David Richardson a808c6fbab Refactor CPTimeZone to utilize native JavaScript timezone APIs
Remove the legacy, locally-bundled tzdata payload and re-implement CPTimeZone to wrap the host JavaScript engine's native timezone capabilities.
This uses fundamental properties of the host Javascript environment and is supported by browsers and Node.

* Transition offset calculations, abbreviation lookups, and DST evaluations to rely on native temporal data via underlying bridging functions (e.g., `_offsetMinutesForZone`, `_abbreviationForNameAndDate`).
* Implement synthetic fallback logic for fixed-offset abbreviations when native engines fail to produce IANA short names.
* Route localized timezone name resolution (`_localizedNameForZone`) through native formatters.
* Establish deterministic temporal baseline required by CPDateFormatter test suites.

Eliminates the maintenance burden of updating a bundled tzdata package and guarantees timezone resolution remains synchronized with the host environment.
2026-09-11 18:36:12 -06:00
David Richardson 71c2501ff6 Update CPTimeZoneTest temporal baselines
Expand test coverage for timezone parsing, offset evaluation, and GMT validation.

Establishes a strict temporal baseline and formally exposes existing logic flaws in CPTimeZone prior to applying implementation fixes.
2026-09-11 18:28:15 -06:00
David Richardson 23dff002a4 Fix CPTimeZone initialization and bridge prototype exceptions
The object returned by the host engine's Intl.supportedValuesOf("timeZone") lacks standard JavaScript Array prototype methods (e.g., slice, indexOf) when crossing the runtime bridge.

This previously caused exceptions in testKnownTimeZoneNamesUsesIntlWhenAvailable.

This commit resolves the exceptions by utilizing primitive JavaScript property access and zero-indexed iteration to construct a local array. This architecture safely isolates the class from bridge prototype limitations and CPArray dependencies.

Additionally, it explicitly appends the legacy aliases "GMT" and "UTC" during the manual array construction. Engines adhering to canonical IANA identifiers omit these aliases, which caused localTimeZone initialization to abort in UTC-bound CI environments.

Guaranteeing their presence resolves the null evaluation failure in testSecondsFromGMTForDate.
2026-08-28 19:46:46 -06:00
David Richardson 03b875697e Fix CPTimeZone initialization failure in UTC environments
Intl.supportedValuesOf("timeZone") returns canonical IANA identifiers, omitting legacy aliases such as "GMT" and "UTC". This causes localTimeZone to evaluate to nil when the host engine operates in a UTC time zone, as abbreviationDictionary statically maps these aliases.

We explicitly append "GMT" and "UTC" to the dynamic knownTimeZoneNames array. This ensures invariant preservation for static dictionary lookups, guarantees successful object initialization across all UTC-bound environments, and resolves the evaluation in testSecondsFromGMTForDate on CI runners.
2026-08-28 19:22:56 -06:00
David Richardson d717e07d5c Add offset-based fallback for local-zone abbreviation resolution
* Fix a GitHub CI failure on a UTC-configured runner. Name-based resolution previously found no candidate, and abbreviationForDate returned no value.

* Add a fallback mechanism that uses the system's current UTC offset when a name match fails.

* Ensure correct abbreviation resolution, regardless of the zone name string that the runtime reports.
2026-08-28 19:07:32 -06:00
David Richardson c39f03823a Replace date-string parsing in CPTimeZone with Intl API
* Update abbreviationForDate and _abbreviationForNameAndDate to read the short time zone name directly from Intl.DateTimeFormat(...).formatToParts(). This replaces regular expression parsing of date strings.

 * Update knownTimeZoneNames to use Intl.supportedValuesOf('timeZone') to retrieve the complete IANA time zone set. The method falls back to the legacy 48-city list if Intl is unavailable.

* Replace duplicate regular expression logic in testInitWithNameRespectsDaylightSaving with a direct Intl call.

* Add pinning tests for the recently corrected offsets and the unchanged MSD value.

* Add a feature-detected test for the knownTimeZoneNames upgrade.

* Add two disabled tests to document unresolved gaps: non-English localizedName outputs and ambiguous reverse offset lookups.

* The full IANA-identity redesign as a separate task. Abbreviation-keyed lookups, colliding offsets, and English-only localizedName limitations remain unresolved in this interim fix.
2026-08-28 14:19:46 -06:00
David Richardson f3a04f23f8 Fix incorrect UTC offsets in CPTimeZone abbreviation table
* Correct timeDifferenceFromUTC values for MDT, WAT, NZDT, NZST, and WIT.

* Update MSK to the current constant UTC+3 offset. Russia abolished Daylight Saving Time in 2014.

* Leave MSD unchanged. Add an inline comment explaining that Moscow Summer Time no longer exists and assigning a new offset would fabricate data.

* Track future work to replace this static table with Intl-backed lookup from browsers’ internal values.

This future lookup will include a protocol seam for:
* runtimes without complete timezone data.
* developers who cannot tolerate non-current information from browser update latency or have other individual need.
2026-08-28 13:59:05 -06:00
David Richardson 1a9a42ff54 Replace #pragma mark with // MARK:
Replace objc directive with native Javascript version // MARK: to facilitate elimination of preproccsing pass.
2026-07-21 15:15:53 -06:00
daboe01andGitHub c41307dc37 Merge branch 'main' into fixed-CPTimeZone-initWithName-does-not-return-the-timeZone-with-the-good-daylight-saving- 2025-07-05 12:58:01 +02:00
daboe01 74f204e6fa fixed: tests and implementation 2025-06-29 20:20:58 +02:00
daboe01 bb6b738fc7 fixed: CPTimeZone initWithName: does not return the timeZone with the good daylight saving 2025-06-29 19:34:56 +02:00
daboe01 db51d5ca54 fixed: time zone methods return nil in Chrome and Firefox 2025-06-22 19:27:58 +02:00
Martin Carlberg d9791673df Fixed: Make sure we can build on Linux. Tested on Ubuntu 20.04 2021-11-07 13:41:01 +00:00
Martin Carlberg 9e6f1e0dc3 Fixed: Timezone abbreviation was not working with the latest changes on all setups.
This is still not 100% but looks like it works a little bit better
2021-09-21 15:38:51 +02:00
Martin Carlberg 24bf09b70c Fixed: Abbreviation for a timezone is not handled in JavaScript. This changes makes it better but not perfect. 2021-09-21 10:30:26 +02:00
Alexandre Wilhelm 34f724a4a4 Fixed: capp_lint fixes 2015-04-22 11:22:44 -07:00
Antoine Mercadal 45248bcb65 FIXED: ivars warning fixes 2014-11-06 12:17:58 -08:00
Aparajita Fishman 391ff7279d Fixed: capp_lint errors. 2013-05-16 15:02:45 -04:00
Alexandre Wilhelm 0bbaec0829 New: Added support for CPTimeZone and CPDateFormatter
- Added support for CPDateFormatter in Foundation
- Added support for CPTimeZone in Foundation
- Added support fo CPDateFormatter in nib2cib

Test app in Tests/Manual/CPDateFormatter
UnitTest in Tests/Foundation/CPTimeZoneTest.j
UnitTest in Tests/Foundation/CPDateFormatterTest.j
2013-04-12 11:15:10 -07:00