barefoot_js 0.21.4 → 0.23.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.
- checksums.yaml +4 -4
- data/lib/barefoot_js.rb +74 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c491246ea9391fca494777435815f8dccaa0be41243f3c87b761f93bcde0f43f
|
|
4
|
+
data.tar.gz: ee67f4181d862e7bcce29dfeeb94f261e6528a20239c5492892d7c7afacae5d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba5295b8b075327c8a99e27b4031d7027a4fd49acc66f770c8d4a8e0f93a87af27825d2bb3f984b9b50adddbd208da4a7269a68647f6d7b6158403f56ae5e8a6
|
|
7
|
+
data.tar.gz: bf4741049a215dd6b02324294eef094d4cf3b7fabeee5c413e5390c52349c6077c45bd2bb217e9864add8a83a18cbb40a33c1f7e2d4db4e2e0ca64aebcf96496
|
data/lib/barefoot_js.rb
CHANGED
|
@@ -529,6 +529,80 @@ module BarefootJS
|
|
|
529
529
|
end
|
|
530
530
|
end
|
|
531
531
|
|
|
532
|
+
# `tz` shapes FORMAT_DATE_OFFSET_RE matches: a fixed UTC offset `±HH:MM`
|
|
533
|
+
# (`'+09:00'`, `'-05:30'`) -- the ONLY non-UTC shape `format_date`
|
|
534
|
+
# recognizes (mirrors OFFSET_RE in packages/client/src/format-date.ts).
|
|
535
|
+
FORMAT_DATE_OFFSET_RE = /\A([+-])(\d{2}):(\d{2})\z/
|
|
536
|
+
|
|
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`.
|
|
551
|
+
#
|
|
552
|
+
# recv: the same receiver contract as `date` above -- a native `Time` or
|
|
553
|
+
# an ISO-8601 string, normalized identically. A nil / unparseable
|
|
554
|
+
# receiver renders '' (never raises mid-render).
|
|
555
|
+
#
|
|
556
|
+
# tz: a fixed UTC offset `±HH:MM` shifts the instant by
|
|
557
|
+
# sign*(HH*60+MM) minutes; ANY other value -- 'UTC', an IANA zone name
|
|
558
|
+
# ('Asia/Tokyo'), or a malformed offset ('+9:00') -- normalizes to a
|
|
559
|
+
# zero-minute shift (UTC), so every backend degrades identically instead
|
|
560
|
+
# of dragging in host tzdata. The shifted instant's UTC calendar fields
|
|
561
|
+
# (not the original instant's) are what pattern tokens read -- the
|
|
562
|
+
# shifted UTC clock face IS the local clock face at that offset. `Time`
|
|
563
|
+
# arithmetic here is exact (Ruby represents the instant as a Rational,
|
|
564
|
+
# not a floor-divided epoch-millis integer), so there's no pre-1970
|
|
565
|
+
# negative-epoch floor-division trap to dodge the way a naive
|
|
566
|
+
# epoch-millis-div-86400000 implementation would hit.
|
|
567
|
+
#
|
|
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)
|
|
574
|
+
t =
|
|
575
|
+
if recv.is_a?(Time)
|
|
576
|
+
recv
|
|
577
|
+
else
|
|
578
|
+
begin
|
|
579
|
+
Time.iso8601(recv.to_s)
|
|
580
|
+
rescue ArgumentError
|
|
581
|
+
nil
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
return '' if t.nil?
|
|
585
|
+
|
|
586
|
+
m = FORMAT_DATE_OFFSET_RE.match(tz.to_s)
|
|
587
|
+
offset_minutes = m ? (m[1] == '-' ? -1 : 1) * ((m[2].to_i * 60) + m[3].to_i) : 0
|
|
588
|
+
|
|
589
|
+
shifted = (t.utc + (offset_minutes * 60)).utc
|
|
590
|
+
year = shifted.year
|
|
591
|
+
month = shifted.mon
|
|
592
|
+
day = shifted.mday
|
|
593
|
+
yyyy = (year.negative? ? '-' : '') + year.abs.to_s.rjust(4, '0')
|
|
594
|
+
|
|
595
|
+
pattern.gsub(FORMAT_DATE_TOKEN_RE) do |token|
|
|
596
|
+
case token
|
|
597
|
+
when 'YYYY' then yyyy
|
|
598
|
+
when 'MM' then format('%02d', month)
|
|
599
|
+
when 'M' then month.to_s
|
|
600
|
+
when 'DD' then format('%02d', day)
|
|
601
|
+
when 'D' then day.to_s
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
end
|
|
605
|
+
|
|
532
606
|
# -----------------------------------------------------------------
|
|
533
607
|
# Array / String method helpers
|
|
534
608
|
# -----------------------------------------------------------------
|
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.
|
|
4
|
+
version: 0.23.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-
|
|
11
|
+
date: 2026-07-19 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.
|