@reykjavik/webtools 0.1.16 → 0.1.17

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.1.17
8
+
9
+ _2024-03-09_
10
+
11
+ - `@reykjavik/webtools/fixIcelandicLocale`:
12
+ - feat: Add support for `DateTimeFormat`'s `dayPeriod` option
13
+
7
14
  ## 0.1.16
8
15
 
9
16
  _2024-03-09_
package/README.md CHANGED
@@ -479,7 +479,8 @@ detection test.)
479
479
  - For `timeZoneName` the values `"long"`, `"shortGeneric"` and `"longGeneric"`
480
480
  will appear in Danish.
481
481
  - The `timeStyle: 'full'` option prints the timezone names in Danish
482
- - The `dayPeriod` option is not supported and prints the day-period in Danish.
482
+ - The `dayPeriod` option has a couple of slight mismatches, at 5 am and 12
483
+ noon.
483
484
 
484
485
  ---
485
486
 
@@ -128,11 +128,22 @@ const weekdays = {
128
128
  lør: 'laugardagur',
129
129
  søn: 'sunnudagur',
130
130
  };
131
+ const dayPeriods = {
132
+ AM: ['f.h.'],
133
+ PM: ['e.h.'],
134
+ 'om natten': ['að nóttu', 'n.'],
135
+ // Mismatch at 05:00 — da: 'om morgenen', is: 'að nóttu'
136
+ 'om morgenen': ['að morgni', 'mrg.'],
137
+ 'om formiddagen': ['að morgni', 'mrg.'],
138
+ // Mismatch at 12:00 — da: 'om eftermiddagen', is: 'hádegi'
139
+ 'om eftermiddagen': ['síðdegis', 'sd.'],
140
+ 'om aftenen': ['að kvöldi', 'kv.'],
141
+ };
131
142
  const partMappers = {
132
143
  month: (value) => {
133
- const islMonth = months[value.slice(0, 3)];
134
- if (islMonth) {
135
- return value.endsWith('.') ? `${islMonth.slice(0, 3)}.` : islMonth;
144
+ const isl = months[value.slice(0, 3)];
145
+ if (isl) {
146
+ return value.endsWith('.') ? `${isl.slice(0, 3)}.` : isl;
136
147
  }
137
148
  },
138
149
  weekday: (value) => {
@@ -150,8 +161,12 @@ const partMappers = {
150
161
  : 'eftir Krist';
151
162
  }
152
163
  },
153
- dayPeriod: (value) => {
154
- return { AM: 'f.h.', PM: 'e.h.' }[value] || value;
164
+ dayPeriod: (value, _, options) => {
165
+ const isl = dayPeriods[value];
166
+ if (isl) {
167
+ const [long, narrow] = isl;
168
+ return options.dayPeriod === 'narrow' ? narrow : long;
169
+ }
155
170
  },
156
171
  literal: (value, lastType) => {
157
172
  if (value === ' den ') {
@@ -166,10 +181,11 @@ const reformatDateTimeParts = function (parts) {
166
181
  if (!this.mapped) {
167
182
  return parts;
168
183
  }
184
+ const options = this.super.resolvedOptions();
169
185
  parts.forEach((part, idx) => {
170
186
  var _a;
171
187
  const mapper = partMappers[part.type];
172
- const newValue = mapper && mapper(part.value, (_a = parts[idx - 1]) === null || _a === void 0 ? void 0 : _a.type);
188
+ const newValue = mapper && mapper(part.value, (_a = parts[idx - 1]) === null || _a === void 0 ? void 0 : _a.type, options);
173
189
  if (newValue != null) {
174
190
  part.value = newValue;
175
191
  }
@@ -133,11 +133,22 @@ const weekdays = {
133
133
  lør: 'laugardagur',
134
134
  søn: 'sunnudagur',
135
135
  };
136
+ const dayPeriods = {
137
+ AM: ['f.h.'],
138
+ PM: ['e.h.'],
139
+ 'om natten': ['að nóttu', 'n.'],
140
+ // Mismatch at 05:00 — da: 'om morgenen', is: 'að nóttu'
141
+ 'om morgenen': ['að morgni', 'mrg.'],
142
+ 'om formiddagen': ['að morgni', 'mrg.'],
143
+ // Mismatch at 12:00 — da: 'om eftermiddagen', is: 'hádegi'
144
+ 'om eftermiddagen': ['síðdegis', 'sd.'],
145
+ 'om aftenen': ['að kvöldi', 'kv.'],
146
+ };
136
147
  const partMappers = {
137
148
  month: (value) => {
138
- const islMonth = months[value.slice(0, 3)];
139
- if (islMonth) {
140
- return value.endsWith('.') ? `${islMonth.slice(0, 3)}.` : islMonth;
149
+ const isl = months[value.slice(0, 3)];
150
+ if (isl) {
151
+ return value.endsWith('.') ? `${isl.slice(0, 3)}.` : isl;
141
152
  }
142
153
  },
143
154
  weekday: (value) => {
@@ -155,8 +166,12 @@ const partMappers = {
155
166
  : 'eftir Krist';
156
167
  }
157
168
  },
158
- dayPeriod: (value) => {
159
- return { AM: 'f.h.', PM: 'e.h.' }[value] || value;
169
+ dayPeriod: (value, _, options) => {
170
+ const isl = dayPeriods[value];
171
+ if (isl) {
172
+ const [long, narrow] = isl;
173
+ return options.dayPeriod === 'narrow' ? narrow : long;
174
+ }
160
175
  },
161
176
  literal: (value, lastType) => {
162
177
  if (value === ' den ') {
@@ -171,10 +186,11 @@ const reformatDateTimeParts = function (parts) {
171
186
  if (!this.mapped) {
172
187
  return parts;
173
188
  }
189
+ const options = this.super.resolvedOptions();
174
190
  parts.forEach((part, idx) => {
175
191
  var _a;
176
192
  const mapper = partMappers[part.type];
177
- const newValue = mapper && mapper(part.value, (_a = parts[idx - 1]) === null || _a === void 0 ? void 0 : _a.type);
193
+ const newValue = mapper && mapper(part.value, (_a = parts[idx - 1]) === null || _a === void 0 ? void 0 : _a.type, options);
178
194
  if (newValue != null) {
179
195
  part.value = newValue;
180
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
5
5
  "main": "index.js",
6
6
  "repository": "ssh://git@github.com:reykjavikcity/webtools.git",