@escape-game-over/atlas 0.1.100 → 0.1.102

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escape-game-over/atlas",
3
- "version": "0.1.100",
3
+ "version": "0.1.102",
4
4
  "type": "module",
5
5
  "description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
6
6
  "private": false,
@@ -10,8 +10,11 @@
10
10
  */
11
11
 
12
12
  export {
13
+ formatTime,
14
+ type HourCycle,
13
15
  type OpenStatus,
14
16
  openStatus,
17
+ type TimeFormat,
15
18
  type VenueNow,
16
19
  } from "../hours.ts";
17
20
  export * from "./attribution.ts";
@@ -28,8 +28,10 @@ export type ContactFormType =
28
28
  | "birthday_party"
29
29
  | "board_games"
30
30
  | "group_booking"
31
+ | "school_trips"
31
32
  | "team_building"
32
- | "voucher";
33
+ | "voucher"
34
+ | "vr_games";
33
35
 
34
36
  /** Where a deployment's contact mail goes. */
35
37
  export interface MailEndpoint {
package/src/hours.ts CHANGED
@@ -164,6 +164,13 @@ export function groupHours(
164
164
  return [...groups.values()];
165
165
  }
166
166
 
167
+ /**
168
+ * Which clock times print on: `"h23"` as written (`14:00`), `"h12"` on a
169
+ * 12-hour clock (`2:00 PM`). Never the locale's default, which gives Greek a
170
+ * 12-hour clock nobody there uses on a door.
171
+ */
172
+ export type HourCycle = "h12" | "h23";
173
+
167
174
  /**
168
175
  * How to print a week. Day names come from `Intl` in `locale`; "closed" is
169
176
  * copy, so the caller translates it.
@@ -175,12 +182,8 @@ export interface HoursFormat {
175
182
  weekday?: "short" | "long";
176
183
  /** The word for a day the venue is shut. */
177
184
  closed: string;
178
- /**
179
- * Times print as written (`14:00`) unless this is `"h12"` (`2:00 PM`).
180
- * Not the locale's default, which gives Greek a 12-hour clock nobody there
181
- * uses on a door.
182
- */
183
- hourCycle?: "h12";
185
+ /** As written (`"h23"`) when absent. */
186
+ hourCycle?: HourCycle;
184
187
  /** Between the ends of a span: `Mon–Thu`, `14:00–23:30`. */
185
188
  between?: string;
186
189
  /** Between spans: `Mon–Thu, Sun`. */
@@ -245,6 +248,7 @@ const SEMICOLONS: Readonly<Record<string, string>> = {
245
248
  fr: "\u202F; ",
246
249
  hu: "; ",
247
250
  it: "; ",
251
+ nl: "; ",
248
252
  pt: "; ",
249
253
  ru: "; ",
250
254
  sv: "; ",
@@ -304,6 +308,33 @@ export function hoursSentence(
304
308
  .join(semicolon);
305
309
  }
306
310
 
311
+ /** How `formatTime` prints a time. */
312
+ export interface TimeFormat {
313
+ /** The language the clock is read in, e.g. `"en-US"`. */
314
+ readonly locale: string;
315
+ /** As written (`"h23"`) when absent. */
316
+ readonly hourCycle?: HourCycle;
317
+ }
318
+
319
+ /**
320
+ * One time as the hours print it: as written (`14:00`), or on a 12-hour clock
321
+ * (`2:00 PM`). For a line that quotes a single time, such as "open until",
322
+ * so it reads like the table beside it.
323
+ */
324
+ export function formatTime(at: TimeOfDay, format: TimeFormat): string {
325
+ if (format.hourCycle !== "h12") return at;
326
+ return new Intl.DateTimeFormat(format.locale, {
327
+ hour: "numeric",
328
+ minute: "2-digit",
329
+ hourCycle: "h12",
330
+ timeZone: "UTC",
331
+ }).format(
332
+ new Date(
333
+ Date.UTC(2024, 0, 1, Number(at.slice(0, 2)), Number(at.slice(3, 5)))
334
+ )
335
+ );
336
+ }
337
+
307
338
  /** Day names and times as `format` prints them. */
308
339
  function printer(
309
340
  format: Pick<HoursFormat, "locale" | "weekday" | "hourCycle">
@@ -315,29 +346,7 @@ function printer(
315
346
  });
316
347
  const dayName = (day: Weekday): string =>
317
348
  names.format(new Date(Date.UTC(2024, 0, 1 + WEEK.indexOf(day))));
318
- const clock =
319
- format.hourCycle === "h12"
320
- ? new Intl.DateTimeFormat(format.locale, {
321
- hour: "numeric",
322
- minute: "2-digit",
323
- hourCycle: "h12",
324
- timeZone: "UTC",
325
- })
326
- : undefined;
327
- const time = (at: TimeOfDay): string =>
328
- clock === undefined
329
- ? at
330
- : clock.format(
331
- new Date(
332
- Date.UTC(
333
- 2024,
334
- 0,
335
- 1,
336
- Number(at.slice(0, 2)),
337
- Number(at.slice(3, 5))
338
- )
339
- )
340
- );
349
+ const time = (at: TimeOfDay): string => formatTime(at, format);
341
350
  return { dayName, time };
342
351
  }
343
352
 
package/src/index.ts CHANGED
@@ -120,13 +120,16 @@ export {
120
120
  type DayHours,
121
121
  type FormattedHours,
122
122
  formatHours,
123
+ formatTime,
123
124
  groupHours,
125
+ type HourCycle,
124
126
  type HoursFormat,
125
127
  type HoursGroup,
126
128
  type HoursSentenceFormat,
127
129
  hoursSentence,
128
130
  type OpenStatus,
129
131
  openStatus,
132
+ type TimeFormat,
130
133
  type TimeOfDay,
131
134
  type TimeRange,
132
135
  type VenueNow,