pythonlib 0.1.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.
Files changed (66) hide show
  1. package/README.md +183 -0
  2. package/dist/chunk-3CSEXTA7.js +376 -0
  3. package/dist/chunk-3CSEXTA7.js.map +1 -0
  4. package/dist/chunk-HA5Y7PKO.js +680 -0
  5. package/dist/chunk-HA5Y7PKO.js.map +1 -0
  6. package/dist/chunk-IVYYI2VR.js +261 -0
  7. package/dist/chunk-IVYYI2VR.js.map +1 -0
  8. package/dist/chunk-OMQNGE6T.js +245 -0
  9. package/dist/chunk-OMQNGE6T.js.map +1 -0
  10. package/dist/chunk-P3SGIF72.js +107 -0
  11. package/dist/chunk-P3SGIF72.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-TJFGYXBJ.js +310 -0
  15. package/dist/chunk-TJFGYXBJ.js.map +1 -0
  16. package/dist/chunk-TOI6IG3T.js +337 -0
  17. package/dist/chunk-TOI6IG3T.js.map +1 -0
  18. package/dist/chunk-UFMTN4T4.js +215 -0
  19. package/dist/chunk-UFMTN4T4.js.map +1 -0
  20. package/dist/chunk-V63LKSA3.js +423 -0
  21. package/dist/chunk-V63LKSA3.js.map +1 -0
  22. package/dist/chunk-WAONBJE5.js +236 -0
  23. package/dist/chunk-WAONBJE5.js.map +1 -0
  24. package/dist/collections-xN9Gi0TA.d.ts +113 -0
  25. package/dist/collections.d.ts +1 -0
  26. package/dist/collections.js +12 -0
  27. package/dist/collections.js.map +1 -0
  28. package/dist/datetime-DRwFAiGV.d.ts +139 -0
  29. package/dist/datetime.d.ts +1 -0
  30. package/dist/datetime.js +22 -0
  31. package/dist/datetime.js.map +1 -0
  32. package/dist/functools-St5GqpKG.d.ts +125 -0
  33. package/dist/functools.d.ts +1 -0
  34. package/dist/functools.js +32 -0
  35. package/dist/functools.js.map +1 -0
  36. package/dist/index.d.ts +624 -0
  37. package/dist/index.js +1332 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/itertools-Bj8XivI6.d.ts +138 -0
  40. package/dist/itertools.d.ts +1 -0
  41. package/dist/itertools.js +44 -0
  42. package/dist/itertools.js.map +1 -0
  43. package/dist/json-Xpk0kwSd.d.ts +77 -0
  44. package/dist/json.d.ts +1 -0
  45. package/dist/json.js +14 -0
  46. package/dist/json.js.map +1 -0
  47. package/dist/math-BrT4Aw3E.d.ts +147 -0
  48. package/dist/math.d.ts +1 -0
  49. package/dist/math.js +96 -0
  50. package/dist/math.js.map +1 -0
  51. package/dist/os-FRSJbEUH.d.ts +143 -0
  52. package/dist/os.d.ts +1 -0
  53. package/dist/os.js +58 -0
  54. package/dist/os.js.map +1 -0
  55. package/dist/random-D5S5iSV3.d.ts +72 -0
  56. package/dist/random.d.ts +1 -0
  57. package/dist/random.js +42 -0
  58. package/dist/random.js.map +1 -0
  59. package/dist/re-DSxiURqN.d.ts +148 -0
  60. package/dist/re.d.ts +1 -0
  61. package/dist/re.js +52 -0
  62. package/dist/re.js.map +1 -0
  63. package/dist/string.d.ts +166 -0
  64. package/dist/string.js +30 -0
  65. package/dist/string.js.map +1 -0
  66. package/package.json +85 -0
@@ -0,0 +1,680 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-PZ5AY32C.js";
4
+
5
+ // src/datetime.ts
6
+ var datetime_exports = {};
7
+ __export(datetime_exports, {
8
+ MAXYEAR: () => MAXYEAR,
9
+ MINYEAR: () => MINYEAR,
10
+ date: () => date,
11
+ datetime: () => datetime,
12
+ strftime: () => strftime,
13
+ strptime: () => strptime,
14
+ time: () => time,
15
+ timedelta: () => timedelta
16
+ });
17
+ var timedelta = class _timedelta {
18
+ days;
19
+ seconds;
20
+ microseconds;
21
+ constructor(options) {
22
+ let totalMicroseconds = 0;
23
+ if (options) {
24
+ totalMicroseconds += (options.weeks ?? 0) * 7 * 24 * 60 * 60 * 1e6;
25
+ totalMicroseconds += (options.days ?? 0) * 24 * 60 * 60 * 1e6;
26
+ totalMicroseconds += (options.hours ?? 0) * 60 * 60 * 1e6;
27
+ totalMicroseconds += (options.minutes ?? 0) * 60 * 1e6;
28
+ totalMicroseconds += (options.seconds ?? 0) * 1e6;
29
+ totalMicroseconds += (options.milliseconds ?? 0) * 1e3;
30
+ totalMicroseconds += options.microseconds ?? 0;
31
+ }
32
+ const sign = totalMicroseconds < 0 ? -1 : 1;
33
+ totalMicroseconds = Math.abs(totalMicroseconds);
34
+ this.microseconds = sign * (totalMicroseconds % 1e6);
35
+ totalMicroseconds = Math.floor(totalMicroseconds / 1e6);
36
+ this.seconds = sign * (totalMicroseconds % (24 * 60 * 60));
37
+ this.days = sign * Math.floor(totalMicroseconds / (24 * 60 * 60));
38
+ if (this.microseconds < 0) {
39
+ ;
40
+ this.microseconds += 1e6;
41
+ this.seconds -= 1;
42
+ }
43
+ if (this.seconds < 0) {
44
+ ;
45
+ this.seconds += 24 * 60 * 60;
46
+ this.days -= 1;
47
+ }
48
+ }
49
+ total_seconds() {
50
+ return this.days * 24 * 60 * 60 + this.seconds + this.microseconds / 1e6;
51
+ }
52
+ toString() {
53
+ const parts = [];
54
+ if (this.days !== 0) {
55
+ parts.push(`${String(this.days)} day${Math.abs(this.days) !== 1 ? "s" : ""}`);
56
+ }
57
+ const hours = Math.floor(this.seconds / 3600);
58
+ const minutes = Math.floor(this.seconds % 3600 / 60);
59
+ const secs = this.seconds % 60;
60
+ const timeStr = `${String(hours)}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
61
+ if (this.microseconds > 0) {
62
+ parts.push(`${timeStr}.${String(this.microseconds).padStart(6, "0")}`);
63
+ } else {
64
+ parts.push(timeStr);
65
+ }
66
+ return parts.join(", ");
67
+ }
68
+ add(other) {
69
+ return new _timedelta({
70
+ days: this.days + other.days,
71
+ seconds: this.seconds + other.seconds,
72
+ microseconds: this.microseconds + other.microseconds
73
+ });
74
+ }
75
+ subtract(other) {
76
+ return new _timedelta({
77
+ days: this.days - other.days,
78
+ seconds: this.seconds - other.seconds,
79
+ microseconds: this.microseconds - other.microseconds
80
+ });
81
+ }
82
+ multiply(n) {
83
+ return new _timedelta({
84
+ microseconds: Math.round(this.total_seconds() * 1e6 * n)
85
+ });
86
+ }
87
+ static min = new _timedelta({ days: -999999999 });
88
+ static max = new _timedelta({
89
+ days: 999999999,
90
+ hours: 23,
91
+ minutes: 59,
92
+ seconds: 59,
93
+ microseconds: 999999
94
+ });
95
+ static resolution = new _timedelta({ microseconds: 1 });
96
+ };
97
+ var date = class _date {
98
+ year;
99
+ month;
100
+ day;
101
+ constructor(year, month, day) {
102
+ if (month < 1 || month > 12) {
103
+ throw new Error("month must be in 1..12");
104
+ }
105
+ const maxDay = new Date(year, month, 0).getDate();
106
+ if (day < 1 || day > maxDay) {
107
+ throw new Error(`day is out of range for month`);
108
+ }
109
+ this.year = year;
110
+ this.month = month;
111
+ this.day = day;
112
+ }
113
+ static today() {
114
+ const now = /* @__PURE__ */ new Date();
115
+ return new _date(now.getFullYear(), now.getMonth() + 1, now.getDate());
116
+ }
117
+ static fromtimestamp(timestamp) {
118
+ const d = new Date(timestamp * 1e3);
119
+ return new _date(d.getFullYear(), d.getMonth() + 1, d.getDate());
120
+ }
121
+ static fromisoformat(dateString) {
122
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateString);
123
+ if (!match || !match[1] || !match[2] || !match[3]) {
124
+ throw new Error(`Invalid isoformat string: '${dateString}'`);
125
+ }
126
+ return new _date(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]));
127
+ }
128
+ static fromordinal(ordinal) {
129
+ const d = new Date(Date.UTC(1, 0, ordinal));
130
+ return new _date(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate());
131
+ }
132
+ replace(options) {
133
+ return new _date(
134
+ options?.year ?? this.year,
135
+ options?.month ?? this.month,
136
+ options?.day ?? this.day
137
+ );
138
+ }
139
+ toordinal() {
140
+ const d = new Date(Date.UTC(this.year, this.month - 1, this.day));
141
+ const epoch = new Date(Date.UTC(1, 0, 1));
142
+ return Math.floor((d.getTime() - epoch.getTime()) / (24 * 60 * 60 * 1e3)) + 1;
143
+ }
144
+ weekday() {
145
+ const d = new Date(this.year, this.month - 1, this.day);
146
+ return (d.getDay() + 6) % 7;
147
+ }
148
+ isoweekday() {
149
+ return this.weekday() + 1;
150
+ }
151
+ isocalendar() {
152
+ const d = new Date(this.year, this.month - 1, this.day);
153
+ const dayOfYear = Math.floor(
154
+ (d.getTime() - new Date(this.year, 0, 0).getTime()) / (24 * 60 * 60 * 1e3)
155
+ );
156
+ const jan1 = new Date(this.year, 0, 1);
157
+ const jan1Weekday = (jan1.getDay() + 6) % 7;
158
+ let week = Math.floor((dayOfYear + jan1Weekday - 1) / 7);
159
+ let year = this.year;
160
+ if (week < 1) {
161
+ year -= 1;
162
+ week = 52;
163
+ } else if (week > 52) {
164
+ const dec31 = new Date(this.year, 11, 31);
165
+ const dec31Weekday = (dec31.getDay() + 6) % 7;
166
+ if (dec31Weekday < 3) {
167
+ week = 1;
168
+ year += 1;
169
+ }
170
+ }
171
+ return [year, week, this.isoweekday()];
172
+ }
173
+ isoformat() {
174
+ return `${String(this.year)}-${String(this.month).padStart(2, "0")}-${String(this.day).padStart(2, "0")}`;
175
+ }
176
+ strftime(format) {
177
+ return strftime(format, new datetime(this.year, this.month, this.day, 0, 0, 0, 0));
178
+ }
179
+ toString() {
180
+ return this.isoformat();
181
+ }
182
+ __add__(delta) {
183
+ const d = new Date(this.year, this.month - 1, this.day + delta.days);
184
+ return new _date(d.getFullYear(), d.getMonth() + 1, d.getDate());
185
+ }
186
+ __sub__(other) {
187
+ if (other instanceof timedelta) {
188
+ const d = new Date(this.year, this.month - 1, this.day - other.days);
189
+ return new _date(d.getFullYear(), d.getMonth() + 1, d.getDate());
190
+ }
191
+ const d1 = new Date(this.year, this.month - 1, this.day);
192
+ const d2 = new Date(other.year, other.month - 1, other.day);
193
+ const diffMs = d1.getTime() - d2.getTime();
194
+ return new timedelta({ days: Math.floor(diffMs / (24 * 60 * 60 * 1e3)) });
195
+ }
196
+ __lt__(other) {
197
+ return this.toordinal() < other.toordinal();
198
+ }
199
+ __le__(other) {
200
+ return this.toordinal() <= other.toordinal();
201
+ }
202
+ __gt__(other) {
203
+ return this.toordinal() > other.toordinal();
204
+ }
205
+ __ge__(other) {
206
+ return this.toordinal() >= other.toordinal();
207
+ }
208
+ __eq__(other) {
209
+ return this.toordinal() === other.toordinal();
210
+ }
211
+ static min = new _date(1, 1, 1);
212
+ static max = new _date(9999, 12, 31);
213
+ static resolution = new timedelta({ days: 1 });
214
+ };
215
+ var time = class _time {
216
+ hour;
217
+ minute;
218
+ second;
219
+ microsecond;
220
+ tzinfo;
221
+ constructor(hour = 0, minute = 0, second = 0, microsecond = 0) {
222
+ if (hour < 0 || hour > 23) throw new Error("hour must be in 0..23");
223
+ if (minute < 0 || minute > 59) throw new Error("minute must be in 0..59");
224
+ if (second < 0 || second > 59) throw new Error("second must be in 0..59");
225
+ if (microsecond < 0 || microsecond > 999999) throw new Error("microsecond must be in 0..999999");
226
+ this.hour = hour;
227
+ this.minute = minute;
228
+ this.second = second;
229
+ this.microsecond = microsecond;
230
+ this.tzinfo = null;
231
+ }
232
+ static fromisoformat(timeString) {
233
+ const match = /^(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?$/.exec(timeString);
234
+ if (!match || !match[1] || !match[2] || !match[3]) {
235
+ throw new Error(`Invalid isoformat string: '${timeString}'`);
236
+ }
237
+ const microsecond = match[4] ? parseInt(match[4].padEnd(6, "0").slice(0, 6)) : 0;
238
+ return new _time(parseInt(match[1]), parseInt(match[2]), parseInt(match[3]), microsecond);
239
+ }
240
+ replace(options) {
241
+ return new _time(
242
+ options?.hour ?? this.hour,
243
+ options?.minute ?? this.minute,
244
+ options?.second ?? this.second,
245
+ options?.microsecond ?? this.microsecond
246
+ );
247
+ }
248
+ isoformat(timespec = "auto") {
249
+ const hh = String(this.hour).padStart(2, "0");
250
+ const mm = String(this.minute).padStart(2, "0");
251
+ const ss = String(this.second).padStart(2, "0");
252
+ switch (timespec) {
253
+ case "hours":
254
+ return hh;
255
+ case "minutes":
256
+ return `${hh}:${mm}`;
257
+ case "seconds":
258
+ return `${hh}:${mm}:${ss}`;
259
+ case "milliseconds":
260
+ return `${hh}:${mm}:${ss}.${String(Math.floor(this.microsecond / 1e3)).padStart(3, "0")}`;
261
+ case "microseconds":
262
+ return `${hh}:${mm}:${ss}.${String(this.microsecond).padStart(6, "0")}`;
263
+ case "auto":
264
+ default:
265
+ if (this.microsecond > 0) {
266
+ return `${hh}:${mm}:${ss}.${String(this.microsecond).padStart(6, "0")}`;
267
+ }
268
+ return `${hh}:${mm}:${ss}`;
269
+ }
270
+ }
271
+ strftime(format) {
272
+ return strftime(
273
+ format,
274
+ new datetime(1900, 1, 1, this.hour, this.minute, this.second, this.microsecond)
275
+ );
276
+ }
277
+ toString() {
278
+ return this.isoformat();
279
+ }
280
+ static min = new _time(0, 0, 0, 0);
281
+ static max = new _time(23, 59, 59, 999999);
282
+ static resolution = new timedelta({ microseconds: 1 });
283
+ };
284
+ var datetime = class _datetime extends date {
285
+ hour;
286
+ minute;
287
+ second;
288
+ microsecond;
289
+ tzinfo;
290
+ constructor(year, month, day, hour = 0, minute = 0, second = 0, microsecond = 0) {
291
+ super(year, month, day);
292
+ if (hour < 0 || hour > 23) throw new Error("hour must be in 0..23");
293
+ if (minute < 0 || minute > 59) throw new Error("minute must be in 0..59");
294
+ if (second < 0 || second > 59) throw new Error("second must be in 0..59");
295
+ if (microsecond < 0 || microsecond > 999999) throw new Error("microsecond must be in 0..999999");
296
+ this.hour = hour;
297
+ this.minute = minute;
298
+ this.second = second;
299
+ this.microsecond = microsecond;
300
+ this.tzinfo = null;
301
+ }
302
+ static today() {
303
+ return _datetime.now();
304
+ }
305
+ static now() {
306
+ const d = /* @__PURE__ */ new Date();
307
+ return new _datetime(
308
+ d.getFullYear(),
309
+ d.getMonth() + 1,
310
+ d.getDate(),
311
+ d.getHours(),
312
+ d.getMinutes(),
313
+ d.getSeconds(),
314
+ d.getMilliseconds() * 1e3
315
+ );
316
+ }
317
+ static utcnow() {
318
+ const d = /* @__PURE__ */ new Date();
319
+ return new _datetime(
320
+ d.getUTCFullYear(),
321
+ d.getUTCMonth() + 1,
322
+ d.getUTCDate(),
323
+ d.getUTCHours(),
324
+ d.getUTCMinutes(),
325
+ d.getUTCSeconds(),
326
+ d.getUTCMilliseconds() * 1e3
327
+ );
328
+ }
329
+ static fromtimestamp(timestamp) {
330
+ const d = new Date(timestamp * 1e3);
331
+ return new _datetime(
332
+ d.getFullYear(),
333
+ d.getMonth() + 1,
334
+ d.getDate(),
335
+ d.getHours(),
336
+ d.getMinutes(),
337
+ d.getSeconds(),
338
+ d.getMilliseconds() * 1e3
339
+ );
340
+ }
341
+ static utcfromtimestamp(timestamp) {
342
+ const d = new Date(timestamp * 1e3);
343
+ return new _datetime(
344
+ d.getUTCFullYear(),
345
+ d.getUTCMonth() + 1,
346
+ d.getUTCDate(),
347
+ d.getUTCHours(),
348
+ d.getUTCMinutes(),
349
+ d.getUTCSeconds(),
350
+ d.getUTCMilliseconds() * 1e3
351
+ );
352
+ }
353
+ static fromisoformat(s) {
354
+ const match = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?$/.exec(s);
355
+ if (!match || !match[1] || !match[2] || !match[3] || !match[4] || !match[5] || !match[6]) {
356
+ const dateMatch = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
357
+ if (dateMatch && dateMatch[1] && dateMatch[2] && dateMatch[3]) {
358
+ return new _datetime(parseInt(dateMatch[1]), parseInt(dateMatch[2]), parseInt(dateMatch[3]));
359
+ }
360
+ throw new Error(`Invalid isoformat string: '${s}'`);
361
+ }
362
+ const microsecond = match[7] ? parseInt(match[7].padEnd(6, "0").slice(0, 6)) : 0;
363
+ return new _datetime(
364
+ parseInt(match[1]),
365
+ parseInt(match[2]),
366
+ parseInt(match[3]),
367
+ parseInt(match[4]),
368
+ parseInt(match[5]),
369
+ parseInt(match[6]),
370
+ microsecond
371
+ );
372
+ }
373
+ static combine(d, t) {
374
+ return new _datetime(d.year, d.month, d.day, t.hour, t.minute, t.second, t.microsecond);
375
+ }
376
+ static strptime(dateString, format) {
377
+ return strptime(dateString, format);
378
+ }
379
+ replace(options) {
380
+ return new _datetime(
381
+ options?.year ?? this.year,
382
+ options?.month ?? this.month,
383
+ options?.day ?? this.day,
384
+ options?.hour ?? this.hour,
385
+ options?.minute ?? this.minute,
386
+ options?.second ?? this.second,
387
+ options?.microsecond ?? this.microsecond
388
+ );
389
+ }
390
+ date() {
391
+ return new date(this.year, this.month, this.day);
392
+ }
393
+ time() {
394
+ return new time(this.hour, this.minute, this.second, this.microsecond);
395
+ }
396
+ timestamp() {
397
+ const d = new Date(
398
+ this.year,
399
+ this.month - 1,
400
+ this.day,
401
+ this.hour,
402
+ this.minute,
403
+ this.second,
404
+ this.microsecond / 1e3
405
+ );
406
+ return d.getTime() / 1e3;
407
+ }
408
+ isoformat(sep = "T", timespec = "auto") {
409
+ const dateStr = super.isoformat();
410
+ const t = new time(this.hour, this.minute, this.second, this.microsecond);
411
+ return `${dateStr}${sep}${t.isoformat(timespec)}`;
412
+ }
413
+ ctime() {
414
+ const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
415
+ const months = [
416
+ "Jan",
417
+ "Feb",
418
+ "Mar",
419
+ "Apr",
420
+ "May",
421
+ "Jun",
422
+ "Jul",
423
+ "Aug",
424
+ "Sep",
425
+ "Oct",
426
+ "Nov",
427
+ "Dec"
428
+ ];
429
+ const dayName = days[this.weekday()] ?? "???";
430
+ const monthName = months[this.month - 1] ?? "???";
431
+ return `${dayName} ${monthName} ${String(this.day).padStart(2, " ")} ${String(this.hour).padStart(2, "0")}:${String(this.minute).padStart(2, "0")}:${String(this.second).padStart(2, "0")} ${String(this.year)}`;
432
+ }
433
+ strftime(format) {
434
+ return strftime(format, this);
435
+ }
436
+ toString() {
437
+ return this.isoformat(" ");
438
+ }
439
+ __add__(delta) {
440
+ const totalMicroseconds = this.timestamp() * 1e6 + this.microsecond + delta.total_seconds() * 1e6;
441
+ return _datetime.fromtimestamp(totalMicroseconds / 1e6);
442
+ }
443
+ __sub__(other) {
444
+ if (other instanceof timedelta) {
445
+ const totalMicroseconds = this.timestamp() * 1e6 + this.microsecond - other.total_seconds() * 1e6;
446
+ return _datetime.fromtimestamp(totalMicroseconds / 1e6);
447
+ }
448
+ if (other instanceof _datetime) {
449
+ const diff = this.timestamp() - other.timestamp();
450
+ const microDiff = this.microsecond - other.microsecond;
451
+ return new timedelta({ seconds: diff, microseconds: microDiff });
452
+ }
453
+ const d1 = new Date(this.year, this.month - 1, this.day);
454
+ const d2 = new Date(other.year, other.month - 1, other.day);
455
+ const diffMs = d1.getTime() - d2.getTime();
456
+ return new timedelta({ days: Math.floor(diffMs / (24 * 60 * 60 * 1e3)) });
457
+ }
458
+ static min = new _datetime(1, 1, 1, 0, 0, 0, 0);
459
+ static max = new _datetime(9999, 12, 31, 23, 59, 59, 999999);
460
+ static resolution = new timedelta({ microseconds: 1 });
461
+ };
462
+ var WEEKDAY_NAMES = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
463
+ var WEEKDAY_ABBR = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
464
+ var MONTH_NAMES = [
465
+ "",
466
+ "January",
467
+ "February",
468
+ "March",
469
+ "April",
470
+ "May",
471
+ "June",
472
+ "July",
473
+ "August",
474
+ "September",
475
+ "October",
476
+ "November",
477
+ "December"
478
+ ];
479
+ var MONTH_ABBR = [
480
+ "",
481
+ "Jan",
482
+ "Feb",
483
+ "Mar",
484
+ "Apr",
485
+ "May",
486
+ "Jun",
487
+ "Jul",
488
+ "Aug",
489
+ "Sep",
490
+ "Oct",
491
+ "Nov",
492
+ "Dec"
493
+ ];
494
+ function strftime(format, dt) {
495
+ const pad = (n, width = 2) => String(n).padStart(width, "0");
496
+ return format.replace(/%([aAbBcdHIjmMpSUwWxXyYzZ%])/g, (_, code) => {
497
+ switch (code) {
498
+ case "a":
499
+ return WEEKDAY_ABBR[dt.weekday()] ?? "";
500
+ case "A":
501
+ return WEEKDAY_NAMES[dt.weekday()] ?? "";
502
+ case "b":
503
+ return MONTH_ABBR[dt.month] ?? "";
504
+ case "B":
505
+ return MONTH_NAMES[dt.month] ?? "";
506
+ case "c":
507
+ return dt.ctime();
508
+ case "d":
509
+ return pad(dt.day);
510
+ case "H":
511
+ return pad(dt.hour);
512
+ case "I":
513
+ return pad(dt.hour % 12 || 12);
514
+ case "j": {
515
+ const start = new Date(dt.year, 0, 0);
516
+ const diff = new Date(dt.year, dt.month - 1, dt.day).getTime() - start.getTime();
517
+ const dayOfYear = Math.floor(diff / (24 * 60 * 60 * 1e3));
518
+ return pad(dayOfYear, 3);
519
+ }
520
+ case "m":
521
+ return pad(dt.month);
522
+ case "M":
523
+ return pad(dt.minute);
524
+ case "p":
525
+ return dt.hour < 12 ? "AM" : "PM";
526
+ case "S":
527
+ return pad(dt.second);
528
+ case "U": {
529
+ const start = new Date(dt.year, 0, 1);
530
+ const diff = new Date(dt.year, dt.month - 1, dt.day).getTime() - start.getTime();
531
+ const dayOfYear = Math.floor(diff / (24 * 60 * 60 * 1e3));
532
+ const firstSunday = (7 - start.getDay()) % 7;
533
+ return pad(Math.floor((dayOfYear - firstSunday + 7) / 7));
534
+ }
535
+ case "w":
536
+ return String((dt.weekday() + 1) % 7);
537
+ case "W": {
538
+ const start = new Date(dt.year, 0, 1);
539
+ const diff = new Date(dt.year, dt.month - 1, dt.day).getTime() - start.getTime();
540
+ const dayOfYear = Math.floor(diff / (24 * 60 * 60 * 1e3));
541
+ const firstMonday = (8 - start.getDay()) % 7;
542
+ return pad(Math.floor((dayOfYear - firstMonday + 7) / 7));
543
+ }
544
+ case "x":
545
+ return `${pad(dt.month)}/${pad(dt.day)}/${pad(dt.year % 100)}`;
546
+ case "X":
547
+ return `${pad(dt.hour)}:${pad(dt.minute)}:${pad(dt.second)}`;
548
+ case "y":
549
+ return pad(dt.year % 100);
550
+ case "Y":
551
+ return String(dt.year);
552
+ case "z":
553
+ return "";
554
+ // No timezone info
555
+ case "Z":
556
+ return "";
557
+ // No timezone name
558
+ case "%":
559
+ return "%";
560
+ default:
561
+ return `%${code}`;
562
+ }
563
+ });
564
+ }
565
+ function strptime(dateString, format) {
566
+ let year = 1900, month = 1, day = 1, hour = 0, minute = 0, second = 0, microsecond = 0;
567
+ let pos = 0;
568
+ let formatPos = 0;
569
+ while (formatPos < format.length) {
570
+ if (format[formatPos] === "%") {
571
+ formatPos++;
572
+ const code = format[formatPos];
573
+ formatPos++;
574
+ switch (code) {
575
+ case "Y": {
576
+ const match = /^\d{4}/.exec(dateString.slice(pos));
577
+ if (!match) throw new Error("Invalid year");
578
+ year = parseInt(match[0]);
579
+ pos += 4;
580
+ break;
581
+ }
582
+ case "y": {
583
+ const match = /^\d{2}/.exec(dateString.slice(pos));
584
+ if (!match) throw new Error("Invalid year");
585
+ const y = parseInt(match[0]);
586
+ year = y >= 69 ? 1900 + y : 2e3 + y;
587
+ pos += 2;
588
+ break;
589
+ }
590
+ case "m": {
591
+ const match = /^\d{1,2}/.exec(dateString.slice(pos));
592
+ if (!match) throw new Error("Invalid month");
593
+ month = parseInt(match[0]);
594
+ pos += match[0].length;
595
+ break;
596
+ }
597
+ case "d": {
598
+ const match = /^\d{1,2}/.exec(dateString.slice(pos));
599
+ if (!match) throw new Error("Invalid day");
600
+ day = parseInt(match[0]);
601
+ pos += match[0].length;
602
+ break;
603
+ }
604
+ case "H": {
605
+ const match = /^\d{1,2}/.exec(dateString.slice(pos));
606
+ if (!match) throw new Error("Invalid hour");
607
+ hour = parseInt(match[0]);
608
+ pos += match[0].length;
609
+ break;
610
+ }
611
+ case "M": {
612
+ const match = /^\d{1,2}/.exec(dateString.slice(pos));
613
+ if (!match) throw new Error("Invalid minute");
614
+ minute = parseInt(match[0]);
615
+ pos += match[0].length;
616
+ break;
617
+ }
618
+ case "S": {
619
+ const match = /^\d{1,2}/.exec(dateString.slice(pos));
620
+ if (!match) throw new Error("Invalid second");
621
+ second = parseInt(match[0]);
622
+ pos += match[0].length;
623
+ break;
624
+ }
625
+ case "f": {
626
+ const match = /^\d{1,6}/.exec(dateString.slice(pos));
627
+ if (!match) throw new Error("Invalid microsecond");
628
+ microsecond = parseInt(match[0].padEnd(6, "0"));
629
+ pos += match[0].length;
630
+ break;
631
+ }
632
+ case "b":
633
+ case "B": {
634
+ const names = code === "b" ? MONTH_ABBR : MONTH_NAMES;
635
+ let found = false;
636
+ for (let i = 1; i <= 12; i++) {
637
+ const name = names[i];
638
+ if (name && dateString.slice(pos).toLowerCase().startsWith(name.toLowerCase())) {
639
+ month = i;
640
+ pos += name.length;
641
+ found = true;
642
+ break;
643
+ }
644
+ }
645
+ if (!found) throw new Error("Invalid month name");
646
+ break;
647
+ }
648
+ case "%":
649
+ if (dateString[pos] !== "%") throw new Error("Expected %");
650
+ pos++;
651
+ break;
652
+ default:
653
+ break;
654
+ }
655
+ } else {
656
+ const expectedChar = format[formatPos] ?? "";
657
+ if (dateString[pos] !== expectedChar) {
658
+ throw new Error(`Expected '${expectedChar}' at position ${String(pos)}`);
659
+ }
660
+ pos++;
661
+ formatPos++;
662
+ }
663
+ }
664
+ return new datetime(year, month, day, hour, minute, second, microsecond);
665
+ }
666
+ var MINYEAR = 1;
667
+ var MAXYEAR = 9999;
668
+
669
+ export {
670
+ timedelta,
671
+ date,
672
+ time,
673
+ datetime,
674
+ strftime,
675
+ strptime,
676
+ MINYEAR,
677
+ MAXYEAR,
678
+ datetime_exports
679
+ };
680
+ //# sourceMappingURL=chunk-HA5Y7PKO.js.map