barefoot_js 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/barefoot_js.rb +45 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c491246ea9391fca494777435815f8dccaa0be41243f3c87b761f93bcde0f43f
4
- data.tar.gz: ee67f4181d862e7bcce29dfeeb94f261e6528a20239c5492892d7c7afacae5d0
3
+ metadata.gz: 01c03141b87505bcc2834d5acbf460b92def83f0932ab62845fcfdc4ea1a5b45
4
+ data.tar.gz: f51524718fa1c54848ffe68bdbf1ea7f48ef899a5eaaf879ec47ae5ffc436ff4
5
5
  SHA512:
6
- metadata.gz: ba5295b8b075327c8a99e27b4031d7027a4fd49acc66f770c8d4a8e0f93a87af27825d2bb3f984b9b50adddbd208da4a7269a68647f6d7b6158403f56ae5e8a6
7
- data.tar.gz: bf4741049a215dd6b02324294eef094d4cf3b7fabeee5c413e5390c52349c6077c45bd2bb217e9864add8a83a18cbb40a33c1f7e2d4db4e2e0ca64aebcf96496
6
+ metadata.gz: 92165ba796d909d7995b962a3074f537d7709344817abdb78eb1818c76bcec761fcb6d033d7c4660e26bc624dcf91c85978455c7cdcf85e7231ccd43478ae514
7
+ data.tar.gz: 97beda0b52738f73a9b25b3910ce2a6e0eb3c8b274c7613a2ec332147114dcb4c72133310ee5cff89a0f86caa46d63940afae249148323e5b66238044d74dfb7
data/lib/barefoot_js.rb CHANGED
@@ -535,19 +535,28 @@ module BarefootJS
535
535
  FORMAT_DATE_OFFSET_RE = /\A([+-])(\d{2}):(\d{2})\z/
536
536
 
537
537
  # Longest-match pattern-token alternation (mirrors TOKEN_RE in
538
- # packages/client/src/format-date.ts). Order matters: MM before M and DD
539
- # before D so the 2-char token wins at a position where either could
540
- # match -- Ruby's Onigmo engine, like JS's regex engine, resolves
541
- # alternation leftmost-first (not POSIX leftmost-longest), so listing the
542
- # longer alternative first is what makes "MM" consume both characters
543
- # instead of two "M" matches.
544
- FORMAT_DATE_TOKEN_RE = /YYYY|MM|DD|M|D/
545
-
546
- # `format_date(recv, pattern, tz)` (#2324, spec entry "format_date" in
547
- # spec/template-helpers.md) -- the lowering target for
548
- # `formatDate(date, pattern, timeZone)` (packages/client/src/format-date.ts,
549
- # the JS-normative reference this must match byte-for-byte). Total and
550
- # deterministic: no locale, no host timezone, no `Time.now`.
538
+ # packages/client/src/format-date.ts). Order matters: Onigmo, like JS's
539
+ # regex engine, resolves alternation leftmost-first (not POSIX
540
+ # leftmost-longest), so every multi-char token must be listed before any
541
+ # shorter alternative it prefixes -- YYYY before (nothing shorter
542
+ # shares its prefix), MMMM before MMM before MM before M, DD before D,
543
+ # dddd before ddd. (#2334)
544
+ FORMAT_DATE_TOKEN_RE = /YYYY|MMMM|MMM|MM|DD|dddd|ddd|M|D/
545
+
546
+ # `names`-table section offsets (spec/template-helpers.md "format_date",
547
+ # #2334) -- mirrors MONTHS_WIDE/MONTHS_ABBR/WEEKDAYS_WIDE/WEEKDAYS_ABBR in
548
+ # packages/client/src/format-date.ts.
549
+ FORMAT_DATE_MONTHS_WIDE = 0
550
+ FORMAT_DATE_MONTHS_ABBR = 12
551
+ FORMAT_DATE_WEEKDAYS_WIDE = 24
552
+ FORMAT_DATE_WEEKDAYS_ABBR = 31
553
+
554
+ # `format_date(recv, pattern, tz, names)` (#2324/#2334, spec entry
555
+ # "format_date" in spec/template-helpers.md) -- the lowering target for
556
+ # `formatDate(date, pattern, timeZone, names)`
557
+ # (packages/client/src/format-date.ts, the JS-normative reference this
558
+ # must match byte-for-byte). Total and deterministic: no locale, no host
559
+ # timezone, no `Time.now`.
551
560
  #
552
561
  # recv: the same receiver contract as `date` above -- a native `Time` or
553
562
  # an ISO-8601 string, normalized identically. A nil / unparseable
@@ -563,14 +572,24 @@ module BarefootJS
563
572
  # arithmetic here is exact (Ruby represents the instant as a Rational,
564
573
  # not a floor-divided epoch-millis integer), so there's no pre-1970
565
574
  # negative-epoch floor-division trap to dodge the way a naive
566
- # epoch-millis-div-86400000 implementation would hit.
575
+ # epoch-millis-div-86400000 implementation would hit; the shifted
576
+ # `Time#wday` (0 = Sunday) is likewise exact across the epoch boundary,
577
+ # so it doubles directly as the weekday-name table index.
567
578
  #
568
- # pattern: longest-match token substitution (`YYYY|MM|DD|M|D`); every
569
- # other character -- including multi-byte ones like 年/月/日 -- passes
570
- # through literally. `YYYY` is `abs(year)` zero-padded to 4 digits,
571
- # `-`-prefixed for a negative year; `MM`/`DD` zero-pad to 2; `M`/`D` are
572
- # bare.
573
- def format_date(recv, pattern, tz)
579
+ # names: the flat table (#2334) -- `[0..11]` wide months, `[12..23]`
580
+ # abbreviated months, `[24..30]` wide weekdays (Sunday-first, matching
581
+ # the shifted `Time#wday`), `[31..37]` abbreviated weekdays. The caller
582
+ # owns the values (locale selection is never this method's job). An
583
+ # index past a missing/short table renders '' rather than raising.
584
+ #
585
+ # pattern: longest-match token substitution
586
+ # (`YYYY|MMMM|MMM|MM|DD|dddd|ddd|M|D`); every other character --
587
+ # including multi-byte ones like 年/月/日 -- passes through literally.
588
+ # `YYYY` is `abs(year)` zero-padded to 4 digits, `-`-prefixed for a
589
+ # negative year; `MM`/`DD` zero-pad to 2; `M`/`D` are bare; `MMMM`/`MMM`
590
+ # read the month's wide/abbreviated name; `dddd`/`ddd` read the shifted
591
+ # weekday's wide/abbreviated name.
592
+ def format_date(recv, pattern, tz, names = [])
574
593
  t =
575
594
  if recv.is_a?(Time)
576
595
  recv
@@ -590,15 +609,21 @@ module BarefootJS
590
609
  year = shifted.year
591
610
  month = shifted.mon
592
611
  day = shifted.mday
612
+ weekday = shifted.wday # 0 = Sunday, matching the table's Sunday-first layout
593
613
  yyyy = (year.negative? ? '-' : '') + year.abs.to_s.rjust(4, '0')
614
+ name_at = ->(index) { (names[index] || '').to_s }
594
615
 
595
616
  pattern.gsub(FORMAT_DATE_TOKEN_RE) do |token|
596
617
  case token
597
618
  when 'YYYY' then yyyy
619
+ when 'MMMM' then name_at.call(FORMAT_DATE_MONTHS_WIDE + month - 1)
620
+ when 'MMM' then name_at.call(FORMAT_DATE_MONTHS_ABBR + month - 1)
598
621
  when 'MM' then format('%02d', month)
599
622
  when 'M' then month.to_s
600
623
  when 'DD' then format('%02d', day)
601
624
  when 'D' then day.to_s
625
+ when 'dddd' then name_at.call(FORMAT_DATE_WEEKDAYS_WIDE + weekday)
626
+ when 'ddd' then name_at.call(FORMAT_DATE_WEEKDAYS_ABBR + weekday)
602
627
  end
603
628
  end
604
629
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barefoot_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kobaken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-19 00:00:00.000000000 Z
11
+ date: 2026-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Engine-agnostic BarefootJS server runtime targeting ERB, ported from
14
14
  packages/adapter-perl/lib/BarefootJS.pm.