@bbn/bbn 2.0.42 → 2.0.43

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.
@@ -9,14 +9,17 @@ function partsToPattern(parts, resolved, requestedOpts) {
9
9
  const hourCycle = resolved.hourCycle;
10
10
  const hasDayPeriod = parts.some(p => p.type === 'dayPeriod');
11
11
  const is12h = hasDayPeriod || hourCycle === 'h12' || hourCycle === 'h11';
12
- // ALL NUMERIC (not 2-digit): year, month and day resolved as "numeric"
13
- const allNumericNonPadded = resolved.year === 'numeric' &&
14
- resolved.month === 'numeric' &&
15
- resolved.day === 'numeric';
12
+ const hasYear = !!requestedOpts.year;
13
+ const hasMonth = !!requestedOpts.month;
14
+ const hasDay = !!requestedOpts.day;
15
+ const hasWeekday = !!requestedOpts.weekday;
16
+ const hasTextMonth = requestedOpts.month === 'short' || requestedOpts.month === 'long';
17
+ // "Whole numeric date" = year+month+day, all numeric, no weekday, no text month
18
+ const isWholeNumericDate = hasYear && hasMonth && hasDay && !hasWeekday && !hasTextMonth;
16
19
  for (const p of parts) {
17
20
  switch (p.type) {
18
21
  case 'year': {
19
- // Use YY only if locale actually resolved 2-digit
22
+ // Keep YY when the locale actually resolved to 2-digit
20
23
  if (resolved.year === '2-digit') {
21
24
  pattern += 'YY';
22
25
  }
@@ -31,24 +34,23 @@ function partsToPattern(parts, resolved, requestedOpts) {
31
34
  pattern += requestedOpts.month === 'long' ? 'MMMM' : 'MMM';
32
35
  break;
33
36
  }
34
- // ALL NUMERIC and non-padded → always use M
35
- if (allNumericNonPadded) {
37
+ if (isWholeNumericDate) {
38
+ // whole numeric date → always use M (accepts 1–2 digits)
36
39
  pattern += 'M';
37
40
  break;
38
41
  }
39
- // numeric / 2-digit generic case
42
+ // other numeric month cases (e.g. year–month or month–day)
40
43
  if (/^\d+$/.test(p.value)) {
41
44
  pattern += p.value.length === 2 ? 'MM' : 'M';
42
45
  }
43
46
  else {
44
- // fallback (shouldn't really happen without text month)
45
47
  pattern += p.value.length > 3 ? 'MMMM' : 'MMM';
46
48
  }
47
49
  break;
48
50
  }
49
51
  case 'day': {
50
- // ALL NUMERIC and non-padded → always use D
51
- if (allNumericNonPadded) {
52
+ if (isWholeNumericDate) {
53
+ // whole numeric date → always use D (accepts 1–2 digits)
52
54
  pattern += 'D';
53
55
  break;
54
56
  }
@@ -89,15 +91,9 @@ function partsToPattern(parts, resolved, requestedOpts) {
89
91
  pattern += 'z';
90
92
  break;
91
93
  case 'literal': {
92
- // Wrap literals in [ ... ] so your parser won't confuse them with tokens
93
94
  if (p.value.length) {
94
- if (![' ', ',', '/', '-', ':', '.'].includes(p.value)) {
95
- const v = p.value.replace(/]/g, '\\]');
96
- pattern += `[${v}]`;
97
- }
98
- else {
99
- pattern += p.value;
100
- }
95
+ const v = p.value.replace(/]/g, '\\]');
96
+ pattern += `[${v}]`;
101
97
  }
102
98
  break;
103
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.42",
3
+ "version": "2.0.43",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",