Skip to content

[migration/ilib-js-to-dart] Convert ILibDateFmt, ILibDate, and Calendar systems to pure Dart#63

Open
gouniLee wants to merge 13 commits into
migration/ilib-js-to-dartfrom
converDate
Open

[migration/ilib-js-to-dart] Convert ILibDateFmt, ILibDate, and Calendar systems to pure Dart#63
gouniLee wants to merge 13 commits into
migration/ilib-js-to-dartfrom
converDate

Conversation

@gouniLee
Copy link
Copy Markdown
Contributor

Checklist

The following lists affects Pub Points on pub.dev when the package is published.

  • Passed the all tests.
  • Verified that the example app works.
  • Executed the dart format command.
  • Added the API description is added if necessary.

note. The code for migrating flutter_ilib to Dart will be merged into the migration/ilib-js-to-dart branch, and once all code has been fully converted, it will be merged into the develop branch at once.

Description

Remove JavaScript interop (flutter_js) from ILibDateFmt and ILibDate, replacing
with pure Dart implementations. Implement 9 calendar systems, timezone/DST calculation,
and astronomical computations entirely in Dart using JSON locale data.

Changes

Date Formatting (lib/ilib_datefmt.dart)

  • Rewrite ILibDateFmt to read ilib.data.dateformats and ilib.data.sysres directly
  • Template-based rendering for all date/time tokens (yyyy, MM, dd, hh, mm, ss, etc.)
  • Meridiem and month/weekday name translation from sysres locale data
  • Cross-calendar conversion via Julian Day when formatter calendar differs from input
  • Raw value preservation when calendars match (avoids normalization, matches JS behavior)

Date Options (lib/ilib_date.dart)

  • Add _toCalendarDate() that delegates to the appropriate calendar date class
  • Calendar-aware getDayOfWeek(), getWeekOfYear(), getEra() via lazy _getCalendarDate()

Timezone (lib/ilib_timezone.dart)

  • Pure Dart DST calculation from ilib.data.zoneinfo JSON
  • UTC offset, DST offset, and timezone abbreviation resolution

Calendar Systems (lib/calendar/)

New implementations for 9 calendars, each with Date + RataDie + Cal classes:

  • Gregorian — standard civil calendar
  • ThaiSolar — Gregorian + 543 year offset (Buddhist Era)
  • Julian — pre-Gregorian civil calendar
  • Islamic — Hijri lunar calendar (civil/tabular)
  • Hebrew — lunisolar calendar with complex leap-year cycle
  • Ethiopic — 13-month calendar (Ge'ez)
  • Coptic — 13-month calendar (Egyptian Christian)
  • Persian Astronomical — equinox-based via ILibAstro calculations
  • Persian Algorithmic — 2820-year leap cycle formula

Astronomical Calculations (lib/calendar/ilib_astro.dart)

  • Spring equinox computation for Persian astronomical calendar
  • Delta-T, nutation, and solar longitude calculations
  • Data sourced from ilib.data.astro JSON coefficients

Infrastructure (lib/ilib_init.dart)

  • Asset manifest pre-check to skip unnecessary file load attempts
  • Enhanced locale data merging for dateformats/sysres/zoneinfo keys

Locale Data

  • Add 218 JSON locale data files for dateformats, sysres, and zoneinfo
  • Regenerated from iLib v14.21.0 (CLDR 46.0)

Design Decisions

  1. Rata Die as interchange format: All cross-calendar conversions go through
    Date → RD → Julian Day → target calendar RD → Date
  2. No normalization on same-calendar formatting: When source date and formatter
    use the same calendar, raw year/month/day values are preserved (JS GregorianDate
    does not normalize; Dart would — so we skip conversion)
  3. Lazy calendar computation: _getCalendarDate() only invoked for
    calendar-dependent tokens (day-of-week, week-of-year)

Tests

  • 90+ locale-specific DateFmt tests converted from JS interop to ILibLoader
  • New calendar unit tests: Gregorian, ThaiSolar, Julian, Islamic, Hebrew,
    Ethiopic, Coptic, Persian (8 test files for RataDie, 8 for CalendarDate)
  • Timezone test suite converted from iLib JS test data

Test Plan

  • flutter test test/datefmt/ — date formatting across 90+ locales
  • flutter test test/calendar/ — calendar calculations
  • flutter test test/timezone/ — timezone/DST resolution
  • flutter analyze — static analysis clean

@gouniLee gouniLee self-assigned this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant