Repository navigation
Expand file tree
/
Copy pathschedule.ts
More file actions
333 lines (292 loc) · 11.4 KB
/
Copy pathschedule.ts
File metadata and controls
333 lines (292 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
* The drip / unlock engine.
*
* This is the thing that makes the app an *ongoing class* rather than a video
* dump, and it is deliberately pure: every function here takes the demo clock
* as an argument and returns a value. Nothing reads `Date.now()`.
*
* Why the demo clock is not the real clock
* ----------------------------------------
* If locks were computed from the wall clock, the demo would look different
* every week and be un-testable. Instead the cohort's week 1 is pinned to
* Monday 20 July 2026 (`COHORT_WEEK_ONE`) and the store holds a `week` number
* from 1 to 8. The dock's "Advance one week" / "Reset to week 1" buttons move
* it, so the drip is visible inside a 60-second demo and identical on every
* machine.
*
* The rule, in full:
* • Self-paced mode: nothing is ever locked.
* • Cohort mode: a module is locked while its `week` is past the demo
* clock's current week. Its lessons inherit that lock and render with the
* unlock date ("Unlocks Mon 3 Aug").
*
* A lesson marked `preview` would be open before enrolment; the seeded
* curriculum marks previews on the course sales page rather than on the
* lesson record, so `isPreviewLesson` reads the index and is exported for the
* course page to use.
*/
import { COHORT_WEEK_ONE, COHORT_WEEKS, MODULES, TOTAL_LESSONS } from "../data/demo";
import type { CourseMode, FlatLesson, Module } from "../data/types";
import { locale, number as fmtNumber, t } from "../i18n/ambient";
/* ------------------------------------------------------ Intl plumbing --- */
/*
* Every label below used to be assembled from hardcoded `DAYS` / `MONTHS`
* arrays and `String.padStart`, which produced US English on a Cairo screen.
* They now go through `Intl`, bound to whatever locale the provider is
* rendering (the ambient bridge, since these are pure functions the tests call
* with no React mounted).
*
* Note what did NOT change: the demo clock. `weekStart` / `demoNow` /
* `liveDate` still pin the cohort to Monday 20 July 2026 and still never read
* `Date.now()`. Only the rendering of those instants is locale-aware — the
* instants themselves are the drip system's fixed points.
*
* The formatters are cached per locale + options: `countdown` and the lesson
* player run once a second, and constructing an `Intl.DateTimeFormat` is by
* far the most expensive thing in this file.
*/
const DTF_CACHE = new Map<string, Intl.DateTimeFormat>();
const NF_CACHE = new Map<string, Intl.NumberFormat>();
function dtf(opts: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {
const key = `${locale()}