fix(date-fns): format() returns formatted string (was undefined)#993
Merged
Conversation
Wires the missing NATIVE_MODULE_TABLE rows for `date-fns` so the
manifest's `method("date-fns", "format", false, _)` actually reaches
`js_datefns_format` at codegen, and rewrites the runtime impl to handle
date-fns's lowercase LDML tokens (`yyyy/MM/dd`) in local time instead of
delegating to the dayjs formatter (which only understands uppercase
tokens and formats in UTC).
proggeramlug
added a commit
that referenced
this pull request
May 18, 2026
PR #993 only emitted runs of repeated letters, so date-fns ordinal tokens like `do` were split into a `d` run ("6") and a lone `o` which fell into the unknown-letter catch-all ("o") — producing "January 6o 2020" instead of "January 6th 2020". Extends the token loop to: - Detect single-letter run + literal `o` over the date-fns ordinal alphabet ([yYQqMLwIdDecihHKkms]o) and emit an English ordinal via a new `english_ordinal()` helper (handles 11/12/13 → "th"). - Differentiate AM/PM by run length: a/aa = AM/PM, aaa = am/pm, aaaa = a.m./p.m., aaaaa = a/p. Test fixture extended to cover yyyy-MM-dd HH:mm:ss, MMMM do yyyy, EEEE, do/Mo/yo, and the four a-variants — all match `node --experimental-strip-types` on date-fns@4.1.0 byte-for-byte.
This was referenced May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import { format } from 'date-fns'; format(new Date(2020, 0, 6), 'yyyy-MM-dd')was compiling and running cleanly but printingundefined. The manifest declaredmethod("date-fns", "format", ...)butNATIVE_MODULE_TABLEinlower_call.rshad nomodule: "date-fns"rows, sonative_module_lookupreturnedNoneand the call fell through to the unknown-native branch.format,parseISO,addDays/Months/Years,differenceInDays/Hours/Minutes,isAfter/Before,startOfDay/endOfDay). Allhas_receiver: falsesince date-fns is a functional API.js_datefns_formatto handle date-fns's lowercase Unicode-LDML tokens (yyyy/MM/dd/HH/mm/ss/...) and format inchrono::Localso the day-of-month matches Node on a non-UTC machine. The prior implementation reusedjs_dayjs_format, which only recognises uppercaseYYYY/DDand formats in UTC — wrong on both counts for date-fns.Test plan
format(new Date(2020, 0, 6), 'yyyy-MM-dd')now prints2020-01-06(matched byte-for-byte againstnode --experimental-strip-types).format(d, 'yyyy'),format(d, 'MM'),format(d, 'dd'),typeof format(d, 'yyyy')all match Node output.test-files/test_date_fns_format.tsextended with end-to-endformat(...)checks alongside the existing regex-token regression cases; existing regex output unchanged.cargo build --release -p perry-runtime -p perry-stdlib -p perry-jsruntime -p perryclean.