@autometa/datetime 0.1.12 → 0.1.14

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
@@ -1,5 +1,19 @@
1
1
  # @autometa/datetime
2
2
 
3
+ ## 0.1.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [0c070cb]
8
+ - @autometa/asserters@0.1.6
9
+ - @autometa/phrases@0.1.10
10
+
11
+ ## 0.1.13
12
+
13
+ ### Patch Changes
14
+
15
+ - 6fe8f64: docs: improved typedocs on public interface
16
+
3
17
  ## 0.1.12
4
18
 
5
19
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -245,36 +245,68 @@ var IsoDateFactory = class {
245
245
  make(daysOffset, timeunit) {
246
246
  return this.dateFactory.make(daysOffset, timeunit).toISOString();
247
247
  }
248
+ /**
249
+ * Attempts to parse a phrase into a date.
250
+ * @param phrase
251
+ * @returns
252
+ */
248
253
  fromPhrase(phrase) {
249
254
  return this.dateFactory.fromPhrase(phrase)?.toISOString();
250
255
  }
256
+ /**
257
+ * Returns the date and time of the day before yesterday
258
+ */
251
259
  get beforeYesterday() {
252
260
  return this.phraseMap.get("beforeYesterday");
253
261
  }
262
+ /**
263
+ * Returns the date and time of yesterday
264
+ */
254
265
  get yesterday() {
255
266
  return this.phraseMap.get("yesterday");
256
267
  }
268
+ /**
269
+ * Returns the date and time of today
270
+ */
257
271
  get today() {
258
272
  return this.phraseMap.get("today");
259
273
  }
274
+ /**
275
+ * Returns the date and time of tomorrow
276
+ */
260
277
  get tomorrow() {
261
278
  return this.phraseMap.get("tomorrow");
262
279
  }
280
+ /**
281
+ * Returns the date and time of the day after tomorrow
282
+ */
263
283
  get afterTomorrow() {
264
284
  return this.phraseMap.get("afterTomorrow");
265
285
  }
286
+ /**
287
+ * Returns the date and time of midnight today
288
+ */
266
289
  get midnight() {
267
290
  return this.phraseMap.get("midnight");
268
291
  }
292
+ /**
293
+ * Returns the date and time of today 1 week ago
294
+ */
269
295
  get lastWeek() {
270
296
  return this.phraseMap.get("lastWeek");
271
297
  }
298
+ /**
299
+ * Returns the date and time of today 1 week from now
300
+ */
272
301
  get nextWeek() {
273
302
  return this.phraseMap.get("nextWeek");
274
303
  }
275
304
  get lastFortnight() {
276
305
  return this.phraseMap.get("lastFortnight");
277
306
  }
307
+ /**
308
+ * Returns the date and time of today 1 fortnight from now
309
+ */
278
310
  get nextFortnight() {
279
311
  return this.phraseMap.get("nextFortnight");
280
312
  }
@@ -300,36 +332,71 @@ var FmtDateFactory = class {
300
332
  make(daysOffset, timeunit) {
301
333
  return this.dateFactory.make(daysOffset, timeunit).toISOString().split("T")[0];
302
334
  }
335
+ /**
336
+ * Attempts to parse a phrase into a date.
337
+ * @param phrase
338
+ * @returns
339
+ */
303
340
  fromPhrase(phrase) {
304
341
  return this.dateFactory.fromPhrase(phrase)?.toISOString().split("T")[0];
305
342
  }
343
+ /**
344
+ * Returns the date and time of the day before yesterday
345
+ */
306
346
  get beforeYesterday() {
307
347
  return this.phraseMap.get("beforeYesterday");
308
348
  }
349
+ /**
350
+ * Returns the date and time of yesterday
351
+ */
309
352
  get yesterday() {
310
353
  return this.phraseMap.get("yesterday");
311
354
  }
355
+ /**
356
+ * Returns the date and time of today
357
+ */
312
358
  get today() {
313
359
  return this.phraseMap.get("today");
314
360
  }
361
+ /**
362
+ * Returns the date and time of tomorrow
363
+ */
315
364
  get tomorrow() {
316
365
  return this.phraseMap.get("tomorrow");
317
366
  }
367
+ /**
368
+ * Returns the date and time of the day after tomorrow
369
+ */
318
370
  get afterTomorrow() {
319
371
  return this.phraseMap.get("afterTomorrow");
320
372
  }
373
+ /**
374
+ * Returns the date and time of midnight today
375
+ */
321
376
  get midnight() {
322
377
  return this.phraseMap.get("midnight");
323
378
  }
379
+ /**
380
+ * Returns the date and time of today 1 week ago
381
+ */
324
382
  get lastWeek() {
325
383
  return this.phraseMap.get("lastWeek");
326
384
  }
385
+ /**
386
+ * Returns the date and time of today 1 week from now
387
+ */
327
388
  get nextWeek() {
328
389
  return this.phraseMap.get("nextWeek");
329
390
  }
391
+ /**
392
+ * Returns the date and time of today 1 fortnight ago
393
+ */
330
394
  get lastFortnight() {
331
395
  return this.phraseMap.get("lastFortnight");
332
396
  }
397
+ /**
398
+ * Returns the date and time of today 1 fortnight from now
399
+ */
333
400
  get nextFortnight() {
334
401
  return this.phraseMap.get("nextFortnight");
335
402
  }
@@ -343,48 +410,104 @@ var DatesObject = class {
343
410
  __privateAdd(this, _iso, new IsoDateFactory(__privateGet(this, _factory)));
344
411
  __privateAdd(this, _fmt, new FmtDateFactory(__privateGet(this, _factory)));
345
412
  }
413
+ /**
414
+ * Switches to the ISO factory, which offers an identical interface
415
+ * but returns ISO strings instead of Date objects.
416
+ *
417
+ * Example: `2020-01-01T00:00:00.000Z`
418
+ */
346
419
  get iso() {
347
420
  return __privateGet(this, _iso);
348
421
  }
422
+ /**
423
+ * Switches to the formatted factory, which offers an identical interface
424
+ * but returns formatted strings instead of Date objects.
425
+ *
426
+ * Example: `2020-01-01`
427
+ */
349
428
  get fmt() {
350
429
  return __privateGet(this, _fmt);
351
430
  }
431
+ /**
432
+ * Returns the current date and time.
433
+ */
352
434
  get now() {
353
435
  return __privateGet(this, _factory).find("now");
354
436
  }
437
+ /**
438
+ * Returns the date and time of the day before yesterday
439
+ */
355
440
  get beforeYesterday() {
356
441
  return __privateGet(this, _factory).find("beforeYesterday");
357
442
  }
443
+ /**
444
+ * Returns the date and time of yesterday
445
+ */
358
446
  get yesterday() {
359
447
  return __privateGet(this, _factory).find("yesterday");
360
448
  }
449
+ /**
450
+ * Returns the date and time of today
451
+ */
361
452
  get today() {
362
453
  return __privateGet(this, _factory).find("today");
363
454
  }
455
+ /**
456
+ * Returns the date and time of tomorrow
457
+ */
364
458
  get tomorrow() {
365
459
  return __privateGet(this, _factory).find("tomorrow");
366
460
  }
461
+ /**
462
+ * Returns the date and time of the day after tomorrow
463
+ */
367
464
  get afterTomorrow() {
368
465
  return __privateGet(this, _factory).find("afterTomorrow");
369
466
  }
467
+ /**
468
+ * Returns the date and time of midnight today
469
+ */
370
470
  get midnight() {
371
471
  return __privateGet(this, _factory).find("midnight");
372
472
  }
473
+ /**
474
+ * Returns the date and time of today 1 week ago
475
+ */
373
476
  get lastWeek() {
374
477
  return __privateGet(this, _factory).find("lastWeek");
375
478
  }
479
+ /**
480
+ * Returns the date and time of today 1 week from now
481
+ */
376
482
  get nextWeek() {
377
483
  return __privateGet(this, _factory).find("nextWeek");
378
484
  }
485
+ /**
486
+ * Returns the date and time of today 2 weeks ago
487
+ */
379
488
  get lastFortnight() {
380
489
  return __privateGet(this, _factory).find("lastFortnight");
381
490
  }
491
+ /**
492
+ * Returns the date and time of today 2 weeks from now
493
+ */
382
494
  get nextFortnight() {
383
495
  return __privateGet(this, _factory).find("nextFortnight");
384
496
  }
497
+ /**
498
+ * Attempts to parse a phrase into a date.
499
+ * @param phrase
500
+ * @returns
501
+ */
385
502
  fromPhrase(phrase) {
386
503
  return __privateGet(this, _factory).fromPhrase(phrase);
387
504
  }
505
+ /**
506
+ * Attempts to parse a phrase into a date.
507
+ * If the phrase is invalid, it will return an invalid date instead of throwing.
508
+ * @param phrase
509
+ * @returns
510
+ */
388
511
  fromPhraseSafe(phrase) {
389
512
  return __privateGet(this, _factory).fromPhraseSafe(phrase);
390
513
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/dates/date-factory.ts","../../src/dates/midnight.ts","../../src/dates/iso-date-factory.ts","../../src/dates/formatted-date-factory.ts","../../src/dates/dates.ts","../../src/time/time.ts"],"sourcesContent":["import { TimeUnit, camel, convertPhrase, collapse } from \"@autometa/phrases\";\nimport { midnight } from \"./midnight\";\nimport { AutomationError, raise } from \"@autometa/errors\";\nimport { ConfirmDefined, ConfirmLengthAtLeast } from \"@autometa/asserters\";\nimport { isValidDate, isValidISODateString, isValidTime, isValidYearMonth } from \"iso-datestring-validator\";\ntype TimeShortcut =\n | \"now\"\n | \"beforeYesterday\"\n | \"yesterday\"\n | \"today\"\n | \"tomorrow\"\n | \"afterTomorrow\"\n | \"midnight\"\n | \"lastWeek\"\n | \"nextWeek\"\n | \"lastFortnight\"\n | \"nextFortnight\";\n\nfunction isTimeShortcut(text: string): text is TimeShortcut {\n const converted = convertPhrase(text, camel);\n const includes = [\n \"now\",\n \"beforeYesterday\",\n \"yesterday\",\n \"today\",\n \"tomorrow\",\n \"afterTomorrow\",\n \"midnight\",\n \"lastWeek\",\n \"nextWeek\",\n \"lastFortnight\",\n \"nextFortnight\"\n ].includes(converted);\n if (!includes) {\n return false;\n }\n return true;\n}\nexport class DateFactory {\n phraseMap = new Map<TimeShortcut, () => Date>([\n [\"now\", () => this.make(0, \"days\")],\n [\"beforeYesterday\", () => this.make(-2, \"days\")],\n [\"yesterday\", () => this.make(-1, \"days\")],\n [\"today\", () => this.make(0, \"days\")],\n [\"tomorrow\", () => this.make(1, \"days\")],\n [\"afterTomorrow\", () => this.make(2, \"days\")],\n [\"nextWeek\", () => this.make(7, \"days\")],\n [\"lastWeek\", () => this.make(-7, \"days\")],\n [\"nextFortnight\", () => this.make(14, \"days\")],\n [\"lastFortnight\", () => this.make(-14, \"days\")],\n [\"midnight\", midnight]\n ]);\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n find(name: TimeShortcut): Date {\n const result = this.phraseMap.get(name);\n if (result) {\n return result();\n }\n raise(\n `Could not find date shortcut ${name}. Please use a valid date shortcut from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n\n fromPhraseSafe(phrase: string) {\n const name = convertPhrase(phrase, camel);\n if (isTimeShortcut(name)) {\n if (this.phraseMap.has(name)) {\n return this.phraseMap.get(name)?.call(this);\n }\n }\n \n const matchDay = this.#extractTimeFromPhrase(phrase);\n if (matchDay) {\n return matchDay;\n }\n const first = isValidDate(phrase);\n const second = isValidISODateString(phrase);\n const third = isValidTime(phrase);\n const fourth = isValidYearMonth(phrase);\n if (!first && !second && !third && !fourth) {\n return new Date(\"null\");\n }\n const parsed = new Date(phrase);\n if (isNaN(parsed.getTime())) {\n return new Date(Date.parse(phrase));\n }\n return parsed;\n }\n fromPhrase(phrase: string) {\n const result = this.fromPhraseSafe(phrase);\n if (result) {\n return result;\n }\n raise(\n `Could not parse date from phrase ${phrase}. Please use a valid date string or a phrase from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n make(timeOffset: number, timeunit: TimeUnit) {\n const unit = timeunit.endsWith(\"s\") ? timeunit : `${timeunit}s`;\n switch (unit) {\n case \"years\":\n return this.#addYears(timeOffset);\n case \"months\":\n return this.#addMonths(timeOffset);\n case \"weeks\":\n return this.#addWeeks(timeOffset);\n case \"days\":\n return this.#addDays(timeOffset);\n case \"seconds\":\n return this.#addSeconds(timeOffset);\n case \"milliseconds\":\n return this.#addMilliseconds(timeOffset);\n case \"hours\":\n return this.#addHours(timeOffset);\n case \"minutes\":\n return this.#addMinutes(timeOffset);\n default:\n throw new AutomationError(\n `Invalid timeunit ${timeunit}, options are 'days', 'seconds', 'milliseconds', 'hours', 'minutes'. Non plural equivalents such as 'day' or 'week' are also accepted.`\n );\n }\n }\n #extractTimeFromPhrase(phrase: string) {\n return (\n this.#extractFutureFromPhrase(phrase) ??\n this.#extractPastFromPhrase(phrase)\n );\n }\n #extractFutureFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)s? from now?/;\n const pastMatch = pastPattern.exec(phrase);\n\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, collapse) as TimeUnit;\n return this.make(Number(value), timeunit);\n }\n }\n #extractPastFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)(s)? ago?/gm;\n const pastMatch = pastPattern.exec(phrase);\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, camel) as TimeUnit;\n return this.make(-Number(value), timeunit);\n }\n }\n #addYears(yearsOffset: number) {\n const date = new Date();\n date.setFullYear(date.getFullYear() + yearsOffset);\n return date;\n }\n #addMonths(monthOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + monthOffset);\n return date;\n }\n #addWeeks(weekOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + weekOffset / 4);\n return date;\n }\n #addDays(daysOffset: number) {\n const date = new Date();\n date.setDate(date.getDate() + daysOffset);\n return date;\n }\n\n #addSeconds(secondsOffset: number) {\n const date = new Date();\n date.setSeconds(date.getSeconds() + secondsOffset);\n return date;\n }\n\n #addMilliseconds(millisecondsOffset: number) {\n const date = new Date();\n date.setMilliseconds(date.getMilliseconds() + millisecondsOffset);\n return date;\n }\n #addHours(hoursOffset: number) {\n const date = new Date();\n date.setHours(date.getHours() + hoursOffset);\n return date;\n }\n #addMinutes(minutesOffset: number) {\n const date = new Date();\n date.setMinutes(date.getMinutes() + minutesOffset);\n return date;\n }\n}\n","\nexport function midnight() {\n const date = new Date();\n date.setDate(date.getDate() + 1);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { midnight } from './midnight';\nimport { DateFactory } from './date-factory';\n\n\nexport class IsoDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory.make(daysOffset, timeunit).toISOString();\n }\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString();\n }\n\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n get today() {\n return this.phraseMap.get('today');\n }\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { DateFactory } from './date-factory';\nimport { midnight } from './midnight';\n\nexport class FmtDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory\n .make(daysOffset, timeunit)\n .toISOString()\n .split('T')[0];\n }\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString().split('T')[0];\n }\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n get today() {\n return this.phraseMap.get('today');\n }\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { DateFactory } from \"./date-factory\";\nimport { IsoDateFactory } from \"./iso-date-factory\";\nimport { FmtDateFactory } from \"./formatted-date-factory\";\nimport { TimeUnit } from \"@autometa/phrases\";\n\nexport class DatesObject {\n #factory: DateFactory = new DateFactory();\n #iso = new IsoDateFactory(this.#factory);\n #fmt = new FmtDateFactory(this.#factory);\n get iso() {\n return this.#iso;\n }\n\n get fmt() {\n return this.#fmt;\n }\n\n get now() {\n return this.#factory.find(\"now\");\n }\n\n get beforeYesterday(): Date {\n return this.#factory.find(\"beforeYesterday\");\n }\n\n get yesterday(): Date {\n return this.#factory.find(\"yesterday\");\n }\n\n get today(): Date {\n return this.#factory.find(\"today\");\n }\n\n get tomorrow(): Date {\n return this.#factory.find(\"tomorrow\");\n }\n\n get afterTomorrow(): Date {\n return this.#factory.find(\"afterTomorrow\");\n }\n\n get midnight(): Date {\n return this.#factory.find(\"midnight\");\n }\n\n get lastWeek(): Date {\n return this.#factory.find(\"lastWeek\");\n }\n\n get nextWeek(): Date {\n return this.#factory.find(\"nextWeek\");\n }\n\n get lastFortnight(): Date {\n return this.#factory.find(\"lastFortnight\");\n }\n\n get nextFortnight(): Date {\n return this.#factory.find(\"nextFortnight\");\n }\n\n fromPhrase(phrase: string) {\n return this.#factory.fromPhrase(phrase);\n }\n\n fromPhraseSafe(phrase: string) {\n return this.#factory.fromPhraseSafe(phrase);\n }\n\n make(timeOffset: number, timeUnit: TimeUnit) {\n return this.#factory.make(timeOffset, timeUnit);\n }\n}\n\nexport const Dates = new DatesObject();\n","import { AssertKey } from \"@autometa/asserters\";\nimport { convertPhrase, lower } from \"@autometa/phrases\";\ntype TimeDiffFn = (date1: Date, date2: Date) => number;\n\nexport class TimeDiff {\n minutes(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 60000;\n }\n seconds(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 1000;\n }\n millis(date1: Date, date2: Date) {\n const d1 = new Date(date1).getTime();\n const d2 = new Date(date2).getTime();\n return Math.abs(Math.round(d2 - d1));\n }\n days(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 86400000;\n }\n hours(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 3600000;\n }\n weeks(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 604800000;\n }\n fromPhrase(phrase: string): TimeDiffFn {\n const propertyKey = convertPhrase(phrase, lower);\n AssertKey(this, propertyKey);\n return (this[propertyKey] as TimeDiffFn).bind(this);\n }\n}\n\nexport class TimeObject {\n #diff = new TimeDiff();\n get diff() {\n return this.#diff;\n }\n}\n\nexport const Time = new TimeObject();\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAmB,OAAO,eAAe,gBAAgB;;;ACClD,SAAS,WAAW;AACzB,QAAM,OAAO,oBAAI,KAAK;AACtB,OAAK,QAAQ,KAAK,QAAQ,IAAI,CAAC;AAC/B,OAAK,SAAS,GAAG,GAAG,GAAG,CAAC;AACxB,SAAO;AACT;;;ADJA,SAAS,iBAAiB,aAAa;AACvC,SAAS,gBAAgB,4BAA4B;AACrD,SAAS,aAAa,sBAAsB,aAAa,wBAAwB;AAcjF,SAAS,eAAe,MAAoC;AAC1D,QAAM,YAAY,cAAc,MAAM,KAAK;AAC3C,QAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,SAAS,SAAS;AACpB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,SAAO;AACT;AArCA;AAsCO,IAAM,cAAN,MAAkB;AAAA,EAAlB;AAyFL;AAMA;AAUA;AASA;AAKA;AAKA;AAKA;AAMA;AAMA;AAKA;AAKA;AAtJA,qBAAY,oBAAI,IAA8B;AAAA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../../src/dates/midnight.ts","../../src/dates/iso-date-factory.ts","../../src/dates/formatted-date-factory.ts","../../src/dates/dates.ts","../../src/time/time.ts"],"sourcesContent":["import { TimeUnit, camel, convertPhrase, collapse } from \"@autometa/phrases\";\nimport { midnight } from \"./midnight\";\nimport { AutomationError, raise } from \"@autometa/errors\";\nimport { ConfirmDefined, ConfirmLengthAtLeast } from \"@autometa/asserters\";\nimport { isValidDate, isValidISODateString, isValidTime, isValidYearMonth } from \"iso-datestring-validator\";\ntype TimeShortcut =\n | \"now\"\n | \"beforeYesterday\"\n | \"yesterday\"\n | \"today\"\n | \"tomorrow\"\n | \"afterTomorrow\"\n | \"midnight\"\n | \"lastWeek\"\n | \"nextWeek\"\n | \"lastFortnight\"\n | \"nextFortnight\";\n\nfunction isTimeShortcut(text: string): text is TimeShortcut {\n const converted = convertPhrase(text, camel);\n const includes = [\n \"now\",\n \"beforeYesterday\",\n \"yesterday\",\n \"today\",\n \"tomorrow\",\n \"afterTomorrow\",\n \"midnight\",\n \"lastWeek\",\n \"nextWeek\",\n \"lastFortnight\",\n \"nextFortnight\"\n ].includes(converted);\n if (!includes) {\n return false;\n }\n return true;\n}\nexport class DateFactory {\n phraseMap = new Map<TimeShortcut, () => Date>([\n [\"now\", () => this.make(0, \"days\")],\n [\"beforeYesterday\", () => this.make(-2, \"days\")],\n [\"yesterday\", () => this.make(-1, \"days\")],\n [\"today\", () => this.make(0, \"days\")],\n [\"tomorrow\", () => this.make(1, \"days\")],\n [\"afterTomorrow\", () => this.make(2, \"days\")],\n [\"nextWeek\", () => this.make(7, \"days\")],\n [\"lastWeek\", () => this.make(-7, \"days\")],\n [\"nextFortnight\", () => this.make(14, \"days\")],\n [\"lastFortnight\", () => this.make(-14, \"days\")],\n [\"midnight\", midnight]\n ]);\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n find(name: TimeShortcut): Date {\n const result = this.phraseMap.get(name);\n if (result) {\n return result();\n }\n raise(\n `Could not find date shortcut ${name}. Please use a valid date shortcut from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n\n fromPhraseSafe(phrase: string) {\n const name = convertPhrase(phrase, camel);\n if (isTimeShortcut(name)) {\n if (this.phraseMap.has(name)) {\n return this.phraseMap.get(name)?.call(this);\n }\n }\n \n const matchDay = this.#extractTimeFromPhrase(phrase);\n if (matchDay) {\n return matchDay;\n }\n const first = isValidDate(phrase);\n const second = isValidISODateString(phrase);\n const third = isValidTime(phrase);\n const fourth = isValidYearMonth(phrase);\n if (!first && !second && !third && !fourth) {\n return new Date(\"null\");\n }\n const parsed = new Date(phrase);\n if (isNaN(parsed.getTime())) {\n return new Date(Date.parse(phrase));\n }\n return parsed;\n }\n fromPhrase(phrase: string) {\n const result = this.fromPhraseSafe(phrase);\n if (result) {\n return result;\n }\n raise(\n `Could not parse date from phrase ${phrase}. Please use a valid date string or a phrase from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n make(timeOffset: number, timeunit: TimeUnit) {\n const unit = timeunit.endsWith(\"s\") ? timeunit : `${timeunit}s`;\n switch (unit) {\n case \"years\":\n return this.#addYears(timeOffset);\n case \"months\":\n return this.#addMonths(timeOffset);\n case \"weeks\":\n return this.#addWeeks(timeOffset);\n case \"days\":\n return this.#addDays(timeOffset);\n case \"seconds\":\n return this.#addSeconds(timeOffset);\n case \"milliseconds\":\n return this.#addMilliseconds(timeOffset);\n case \"hours\":\n return this.#addHours(timeOffset);\n case \"minutes\":\n return this.#addMinutes(timeOffset);\n default:\n throw new AutomationError(\n `Invalid timeunit ${timeunit}, options are 'days', 'seconds', 'milliseconds', 'hours', 'minutes'. Non plural equivalents such as 'day' or 'week' are also accepted.`\n );\n }\n }\n #extractTimeFromPhrase(phrase: string) {\n return (\n this.#extractFutureFromPhrase(phrase) ??\n this.#extractPastFromPhrase(phrase)\n );\n }\n #extractFutureFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)s? from now?/;\n const pastMatch = pastPattern.exec(phrase);\n\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, collapse) as TimeUnit;\n return this.make(Number(value), timeunit);\n }\n }\n #extractPastFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)(s)? ago?/gm;\n const pastMatch = pastPattern.exec(phrase);\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, camel) as TimeUnit;\n return this.make(-Number(value), timeunit);\n }\n }\n #addYears(yearsOffset: number) {\n const date = new Date();\n date.setFullYear(date.getFullYear() + yearsOffset);\n return date;\n }\n #addMonths(monthOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + monthOffset);\n return date;\n }\n #addWeeks(weekOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + weekOffset / 4);\n return date;\n }\n #addDays(daysOffset: number) {\n const date = new Date();\n date.setDate(date.getDate() + daysOffset);\n return date;\n }\n\n #addSeconds(secondsOffset: number) {\n const date = new Date();\n date.setSeconds(date.getSeconds() + secondsOffset);\n return date;\n }\n\n #addMilliseconds(millisecondsOffset: number) {\n const date = new Date();\n date.setMilliseconds(date.getMilliseconds() + millisecondsOffset);\n return date;\n }\n #addHours(hoursOffset: number) {\n const date = new Date();\n date.setHours(date.getHours() + hoursOffset);\n return date;\n }\n #addMinutes(minutesOffset: number) {\n const date = new Date();\n date.setMinutes(date.getMinutes() + minutesOffset);\n return date;\n }\n}\n","\nexport function midnight() {\n const date = new Date();\n date.setDate(date.getDate() + 1);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { midnight } from './midnight';\nimport { DateFactory } from './date-factory';\n\n\nexport class IsoDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory.make(daysOffset, timeunit).toISOString();\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * @param phrase\n * @returns\n */\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString();\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n\n /**\n * Returns the date and time of yesterday\n */\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n\n /**\n * Returns the date and time of today\n */\n get today() {\n return this.phraseMap.get('today');\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n\n /**\n * Returns the date and time of today 1 fortnight from now\n */\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { DateFactory } from './date-factory';\nimport { midnight } from './midnight';\n\nexport class FmtDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory\n .make(daysOffset, timeunit)\n .toISOString()\n .split('T')[0];\n }\n \n /**\n * Attempts to parse a phrase into a date.\n * @param phrase\n * @returns\n */\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString().split('T')[0];\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n\n /**\n * Returns the date and time of yesterday\n */\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n\n /**\n * Returns the date and time of today\n */\n get today() {\n return this.phraseMap.get('today');\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n\n /**\n * Returns the date and time of today 1 fortnight ago\n */\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n\n /**\n * Returns the date and time of today 1 fortnight from now\n */\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { DateFactory } from \"./date-factory\";\nimport { IsoDateFactory } from \"./iso-date-factory\";\nimport { FmtDateFactory } from \"./formatted-date-factory\";\nimport { TimeUnit } from \"@autometa/phrases\";\n\nexport class DatesObject {\n #factory: DateFactory = new DateFactory();\n #iso = new IsoDateFactory(this.#factory);\n #fmt = new FmtDateFactory(this.#factory);\n /**\n * Switches to the ISO factory, which offers an identical interface\n * but returns ISO strings instead of Date objects.\n * \n * Example: `2020-01-01T00:00:00.000Z`\n */\n get iso() {\n return this.#iso;\n }\n\n /**\n * Switches to the formatted factory, which offers an identical interface\n * but returns formatted strings instead of Date objects.\n * \n * Example: `2020-01-01`\n */\n get fmt() {\n return this.#fmt;\n }\n\n /**\n * Returns the current date and time.\n */\n get now() {\n return this.#factory.find(\"now\");\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday(): Date {\n return this.#factory.find(\"beforeYesterday\");\n }\n \n /**\n * Returns the date and time of yesterday\n */\n get yesterday(): Date {\n return this.#factory.find(\"yesterday\");\n }\n\n /**\n * Returns the date and time of today\n */\n get today(): Date {\n return this.#factory.find(\"today\");\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow(): Date {\n return this.#factory.find(\"tomorrow\");\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow(): Date {\n return this.#factory.find(\"afterTomorrow\");\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight(): Date {\n return this.#factory.find(\"midnight\");\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek(): Date {\n return this.#factory.find(\"lastWeek\");\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek(): Date {\n return this.#factory.find(\"nextWeek\");\n }\n\n /**\n * Returns the date and time of today 2 weeks ago\n */\n get lastFortnight(): Date {\n return this.#factory.find(\"lastFortnight\");\n }\n\n /**\n * Returns the date and time of today 2 weeks from now\n */\n get nextFortnight(): Date {\n return this.#factory.find(\"nextFortnight\");\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * @param phrase \n * @returns \n */\n fromPhrase(phrase: string) {\n return this.#factory.fromPhrase(phrase);\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * If the phrase is invalid, it will return an invalid date instead of throwing.\n * @param phrase \n * @returns \n */\n fromPhraseSafe(phrase: string) {\n return this.#factory.fromPhraseSafe(phrase);\n }\n\n make(timeOffset: number, timeUnit: TimeUnit) {\n return this.#factory.make(timeOffset, timeUnit);\n }\n}\n\n/**\n * Date utility option to easily generate common\n * dates around the current date, like 'today', 'midnight',\n * 'tomorrow', 'nextWeek', etc.\n * \n * The Dates utility also supports certain language phrases\n * that might be natural in Cucumber's gherkin syntax, like\n * 'next week', 'last week', 'next fortnight', etc. as well\n * as more dynamic phrases like `1 day ago`, `2 weeks from now`,\n */\nexport const Dates = new DatesObject();\n","import { AssertKey } from \"@autometa/asserters\";\nimport { convertPhrase, lower } from \"@autometa/phrases\";\ntype TimeDiffFn = (date1: Date, date2: Date) => number;\n\nexport class TimeDiff {\n minutes(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 60000;\n }\n seconds(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 1000;\n }\n millis(date1: Date, date2: Date) {\n const d1 = new Date(date1).getTime();\n const d2 = new Date(date2).getTime();\n return Math.abs(Math.round(d2 - d1));\n }\n days(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 86400000;\n }\n hours(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 3600000;\n }\n weeks(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 604800000;\n }\n fromPhrase(phrase: string): TimeDiffFn {\n const propertyKey = convertPhrase(phrase, lower);\n AssertKey(this, propertyKey);\n return (this[propertyKey] as TimeDiffFn).bind(this);\n }\n}\n\nexport class TimeObject {\n #diff = new TimeDiff();\n get diff() {\n return this.#diff;\n }\n}\n\nexport const Time = new TimeObject();\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAmB,OAAO,eAAe,gBAAgB;;;ACClD,SAAS,WAAW;AACzB,QAAM,OAAO,oBAAI,KAAK;AACtB,OAAK,QAAQ,KAAK,QAAQ,IAAI,CAA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O;AACT,WAAO,mBAAK;AAAA,EACd;AACF;AAJE;AAMK,IAAM,OAAO,IAAI,WAAW;","names":["convertPhrase","convertPhrase"]}
package/dist/index.d.cts CHANGED
@@ -15,16 +15,48 @@ declare class IsoDateFactory {
15
15
  constructor(dateFactory: DateFactory);
16
16
  phraseMap: Map<string, string>;
17
17
  make(daysOffset: number, timeunit: TimeUnit): string;
18
+ /**
19
+ * Attempts to parse a phrase into a date.
20
+ * @param phrase
21
+ * @returns
22
+ */
18
23
  fromPhrase(phrase: string): string;
24
+ /**
25
+ * Returns the date and time of the day before yesterday
26
+ */
19
27
  get beforeYesterday(): string | undefined;
28
+ /**
29
+ * Returns the date and time of yesterday
30
+ */
20
31
  get yesterday(): string | undefined;
32
+ /**
33
+ * Returns the date and time of today
34
+ */
21
35
  get today(): string | undefined;
36
+ /**
37
+ * Returns the date and time of tomorrow
38
+ */
22
39
  get tomorrow(): string | undefined;
40
+ /**
41
+ * Returns the date and time of the day after tomorrow
42
+ */
23
43
  get afterTomorrow(): string | undefined;
44
+ /**
45
+ * Returns the date and time of midnight today
46
+ */
24
47
  get midnight(): string | undefined;
48
+ /**
49
+ * Returns the date and time of today 1 week ago
50
+ */
25
51
  get lastWeek(): string | undefined;
52
+ /**
53
+ * Returns the date and time of today 1 week from now
54
+ */
26
55
  get nextWeek(): string | undefined;
27
56
  get lastFortnight(): string | undefined;
57
+ /**
58
+ * Returns the date and time of today 1 fortnight from now
59
+ */
28
60
  get nextFortnight(): string | undefined;
29
61
  }
30
62
 
@@ -33,38 +65,139 @@ declare class FmtDateFactory {
33
65
  constructor(dateFactory: DateFactory);
34
66
  phraseMap: Map<string, string>;
35
67
  make(daysOffset: number, timeunit: TimeUnit): string;
68
+ /**
69
+ * Attempts to parse a phrase into a date.
70
+ * @param phrase
71
+ * @returns
72
+ */
36
73
  fromPhrase(phrase: string): string;
74
+ /**
75
+ * Returns the date and time of the day before yesterday
76
+ */
37
77
  get beforeYesterday(): string | undefined;
78
+ /**
79
+ * Returns the date and time of yesterday
80
+ */
38
81
  get yesterday(): string | undefined;
82
+ /**
83
+ * Returns the date and time of today
84
+ */
39
85
  get today(): string | undefined;
86
+ /**
87
+ * Returns the date and time of tomorrow
88
+ */
40
89
  get tomorrow(): string | undefined;
90
+ /**
91
+ * Returns the date and time of the day after tomorrow
92
+ */
41
93
  get afterTomorrow(): string | undefined;
94
+ /**
95
+ * Returns the date and time of midnight today
96
+ */
42
97
  get midnight(): string | undefined;
98
+ /**
99
+ * Returns the date and time of today 1 week ago
100
+ */
43
101
  get lastWeek(): string | undefined;
102
+ /**
103
+ * Returns the date and time of today 1 week from now
104
+ */
44
105
  get nextWeek(): string | undefined;
106
+ /**
107
+ * Returns the date and time of today 1 fortnight ago
108
+ */
45
109
  get lastFortnight(): string | undefined;
110
+ /**
111
+ * Returns the date and time of today 1 fortnight from now
112
+ */
46
113
  get nextFortnight(): string | undefined;
47
114
  }
48
115
 
49
116
  declare class DatesObject {
50
117
  #private;
118
+ /**
119
+ * Switches to the ISO factory, which offers an identical interface
120
+ * but returns ISO strings instead of Date objects.
121
+ *
122
+ * Example: `2020-01-01T00:00:00.000Z`
123
+ */
51
124
  get iso(): IsoDateFactory;
125
+ /**
126
+ * Switches to the formatted factory, which offers an identical interface
127
+ * but returns formatted strings instead of Date objects.
128
+ *
129
+ * Example: `2020-01-01`
130
+ */
52
131
  get fmt(): FmtDateFactory;
132
+ /**
133
+ * Returns the current date and time.
134
+ */
53
135
  get now(): Date;
136
+ /**
137
+ * Returns the date and time of the day before yesterday
138
+ */
54
139
  get beforeYesterday(): Date;
140
+ /**
141
+ * Returns the date and time of yesterday
142
+ */
55
143
  get yesterday(): Date;
144
+ /**
145
+ * Returns the date and time of today
146
+ */
56
147
  get today(): Date;
148
+ /**
149
+ * Returns the date and time of tomorrow
150
+ */
57
151
  get tomorrow(): Date;
152
+ /**
153
+ * Returns the date and time of the day after tomorrow
154
+ */
58
155
  get afterTomorrow(): Date;
156
+ /**
157
+ * Returns the date and time of midnight today
158
+ */
59
159
  get midnight(): Date;
160
+ /**
161
+ * Returns the date and time of today 1 week ago
162
+ */
60
163
  get lastWeek(): Date;
164
+ /**
165
+ * Returns the date and time of today 1 week from now
166
+ */
61
167
  get nextWeek(): Date;
168
+ /**
169
+ * Returns the date and time of today 2 weeks ago
170
+ */
62
171
  get lastFortnight(): Date;
172
+ /**
173
+ * Returns the date and time of today 2 weeks from now
174
+ */
63
175
  get nextFortnight(): Date;
176
+ /**
177
+ * Attempts to parse a phrase into a date.
178
+ * @param phrase
179
+ * @returns
180
+ */
64
181
  fromPhrase(phrase: string): Date;
182
+ /**
183
+ * Attempts to parse a phrase into a date.
184
+ * If the phrase is invalid, it will return an invalid date instead of throwing.
185
+ * @param phrase
186
+ * @returns
187
+ */
65
188
  fromPhraseSafe(phrase: string): Date | undefined;
66
189
  make(timeOffset: number, timeUnit: TimeUnit): Date;
67
190
  }
191
+ /**
192
+ * Date utility option to easily generate common
193
+ * dates around the current date, like 'today', 'midnight',
194
+ * 'tomorrow', 'nextWeek', etc.
195
+ *
196
+ * The Dates utility also supports certain language phrases
197
+ * that might be natural in Cucumber's gherkin syntax, like
198
+ * 'next week', 'last week', 'next fortnight', etc. as well
199
+ * as more dynamic phrases like `1 day ago`, `2 weeks from now`,
200
+ */
68
201
  declare const Dates: DatesObject;
69
202
 
70
203
  type TimeDiffFn = (date1: Date, date2: Date) => number;
package/dist/index.d.ts CHANGED
@@ -15,16 +15,48 @@ declare class IsoDateFactory {
15
15
  constructor(dateFactory: DateFactory);
16
16
  phraseMap: Map<string, string>;
17
17
  make(daysOffset: number, timeunit: TimeUnit): string;
18
+ /**
19
+ * Attempts to parse a phrase into a date.
20
+ * @param phrase
21
+ * @returns
22
+ */
18
23
  fromPhrase(phrase: string): string;
24
+ /**
25
+ * Returns the date and time of the day before yesterday
26
+ */
19
27
  get beforeYesterday(): string | undefined;
28
+ /**
29
+ * Returns the date and time of yesterday
30
+ */
20
31
  get yesterday(): string | undefined;
32
+ /**
33
+ * Returns the date and time of today
34
+ */
21
35
  get today(): string | undefined;
36
+ /**
37
+ * Returns the date and time of tomorrow
38
+ */
22
39
  get tomorrow(): string | undefined;
40
+ /**
41
+ * Returns the date and time of the day after tomorrow
42
+ */
23
43
  get afterTomorrow(): string | undefined;
44
+ /**
45
+ * Returns the date and time of midnight today
46
+ */
24
47
  get midnight(): string | undefined;
48
+ /**
49
+ * Returns the date and time of today 1 week ago
50
+ */
25
51
  get lastWeek(): string | undefined;
52
+ /**
53
+ * Returns the date and time of today 1 week from now
54
+ */
26
55
  get nextWeek(): string | undefined;
27
56
  get lastFortnight(): string | undefined;
57
+ /**
58
+ * Returns the date and time of today 1 fortnight from now
59
+ */
28
60
  get nextFortnight(): string | undefined;
29
61
  }
30
62
 
@@ -33,38 +65,139 @@ declare class FmtDateFactory {
33
65
  constructor(dateFactory: DateFactory);
34
66
  phraseMap: Map<string, string>;
35
67
  make(daysOffset: number, timeunit: TimeUnit): string;
68
+ /**
69
+ * Attempts to parse a phrase into a date.
70
+ * @param phrase
71
+ * @returns
72
+ */
36
73
  fromPhrase(phrase: string): string;
74
+ /**
75
+ * Returns the date and time of the day before yesterday
76
+ */
37
77
  get beforeYesterday(): string | undefined;
78
+ /**
79
+ * Returns the date and time of yesterday
80
+ */
38
81
  get yesterday(): string | undefined;
82
+ /**
83
+ * Returns the date and time of today
84
+ */
39
85
  get today(): string | undefined;
86
+ /**
87
+ * Returns the date and time of tomorrow
88
+ */
40
89
  get tomorrow(): string | undefined;
90
+ /**
91
+ * Returns the date and time of the day after tomorrow
92
+ */
41
93
  get afterTomorrow(): string | undefined;
94
+ /**
95
+ * Returns the date and time of midnight today
96
+ */
42
97
  get midnight(): string | undefined;
98
+ /**
99
+ * Returns the date and time of today 1 week ago
100
+ */
43
101
  get lastWeek(): string | undefined;
102
+ /**
103
+ * Returns the date and time of today 1 week from now
104
+ */
44
105
  get nextWeek(): string | undefined;
106
+ /**
107
+ * Returns the date and time of today 1 fortnight ago
108
+ */
45
109
  get lastFortnight(): string | undefined;
110
+ /**
111
+ * Returns the date and time of today 1 fortnight from now
112
+ */
46
113
  get nextFortnight(): string | undefined;
47
114
  }
48
115
 
49
116
  declare class DatesObject {
50
117
  #private;
118
+ /**
119
+ * Switches to the ISO factory, which offers an identical interface
120
+ * but returns ISO strings instead of Date objects.
121
+ *
122
+ * Example: `2020-01-01T00:00:00.000Z`
123
+ */
51
124
  get iso(): IsoDateFactory;
125
+ /**
126
+ * Switches to the formatted factory, which offers an identical interface
127
+ * but returns formatted strings instead of Date objects.
128
+ *
129
+ * Example: `2020-01-01`
130
+ */
52
131
  get fmt(): FmtDateFactory;
132
+ /**
133
+ * Returns the current date and time.
134
+ */
53
135
  get now(): Date;
136
+ /**
137
+ * Returns the date and time of the day before yesterday
138
+ */
54
139
  get beforeYesterday(): Date;
140
+ /**
141
+ * Returns the date and time of yesterday
142
+ */
55
143
  get yesterday(): Date;
144
+ /**
145
+ * Returns the date and time of today
146
+ */
56
147
  get today(): Date;
148
+ /**
149
+ * Returns the date and time of tomorrow
150
+ */
57
151
  get tomorrow(): Date;
152
+ /**
153
+ * Returns the date and time of the day after tomorrow
154
+ */
58
155
  get afterTomorrow(): Date;
156
+ /**
157
+ * Returns the date and time of midnight today
158
+ */
59
159
  get midnight(): Date;
160
+ /**
161
+ * Returns the date and time of today 1 week ago
162
+ */
60
163
  get lastWeek(): Date;
164
+ /**
165
+ * Returns the date and time of today 1 week from now
166
+ */
61
167
  get nextWeek(): Date;
168
+ /**
169
+ * Returns the date and time of today 2 weeks ago
170
+ */
62
171
  get lastFortnight(): Date;
172
+ /**
173
+ * Returns the date and time of today 2 weeks from now
174
+ */
63
175
  get nextFortnight(): Date;
176
+ /**
177
+ * Attempts to parse a phrase into a date.
178
+ * @param phrase
179
+ * @returns
180
+ */
64
181
  fromPhrase(phrase: string): Date;
182
+ /**
183
+ * Attempts to parse a phrase into a date.
184
+ * If the phrase is invalid, it will return an invalid date instead of throwing.
185
+ * @param phrase
186
+ * @returns
187
+ */
65
188
  fromPhraseSafe(phrase: string): Date | undefined;
66
189
  make(timeOffset: number, timeUnit: TimeUnit): Date;
67
190
  }
191
+ /**
192
+ * Date utility option to easily generate common
193
+ * dates around the current date, like 'today', 'midnight',
194
+ * 'tomorrow', 'nextWeek', etc.
195
+ *
196
+ * The Dates utility also supports certain language phrases
197
+ * that might be natural in Cucumber's gherkin syntax, like
198
+ * 'next week', 'last week', 'next fortnight', etc. as well
199
+ * as more dynamic phrases like `1 day ago`, `2 weeks from now`,
200
+ */
68
201
  declare const Dates: DatesObject;
69
202
 
70
203
  type TimeDiffFn = (date1: Date, date2: Date) => number;
package/dist/index.js CHANGED
@@ -276,36 +276,68 @@ var IsoDateFactory = class {
276
276
  make(daysOffset, timeunit) {
277
277
  return this.dateFactory.make(daysOffset, timeunit).toISOString();
278
278
  }
279
+ /**
280
+ * Attempts to parse a phrase into a date.
281
+ * @param phrase
282
+ * @returns
283
+ */
279
284
  fromPhrase(phrase) {
280
285
  return this.dateFactory.fromPhrase(phrase)?.toISOString();
281
286
  }
287
+ /**
288
+ * Returns the date and time of the day before yesterday
289
+ */
282
290
  get beforeYesterday() {
283
291
  return this.phraseMap.get("beforeYesterday");
284
292
  }
293
+ /**
294
+ * Returns the date and time of yesterday
295
+ */
285
296
  get yesterday() {
286
297
  return this.phraseMap.get("yesterday");
287
298
  }
299
+ /**
300
+ * Returns the date and time of today
301
+ */
288
302
  get today() {
289
303
  return this.phraseMap.get("today");
290
304
  }
305
+ /**
306
+ * Returns the date and time of tomorrow
307
+ */
291
308
  get tomorrow() {
292
309
  return this.phraseMap.get("tomorrow");
293
310
  }
311
+ /**
312
+ * Returns the date and time of the day after tomorrow
313
+ */
294
314
  get afterTomorrow() {
295
315
  return this.phraseMap.get("afterTomorrow");
296
316
  }
317
+ /**
318
+ * Returns the date and time of midnight today
319
+ */
297
320
  get midnight() {
298
321
  return this.phraseMap.get("midnight");
299
322
  }
323
+ /**
324
+ * Returns the date and time of today 1 week ago
325
+ */
300
326
  get lastWeek() {
301
327
  return this.phraseMap.get("lastWeek");
302
328
  }
329
+ /**
330
+ * Returns the date and time of today 1 week from now
331
+ */
303
332
  get nextWeek() {
304
333
  return this.phraseMap.get("nextWeek");
305
334
  }
306
335
  get lastFortnight() {
307
336
  return this.phraseMap.get("lastFortnight");
308
337
  }
338
+ /**
339
+ * Returns the date and time of today 1 fortnight from now
340
+ */
309
341
  get nextFortnight() {
310
342
  return this.phraseMap.get("nextFortnight");
311
343
  }
@@ -331,36 +363,71 @@ var FmtDateFactory = class {
331
363
  make(daysOffset, timeunit) {
332
364
  return this.dateFactory.make(daysOffset, timeunit).toISOString().split("T")[0];
333
365
  }
366
+ /**
367
+ * Attempts to parse a phrase into a date.
368
+ * @param phrase
369
+ * @returns
370
+ */
334
371
  fromPhrase(phrase) {
335
372
  return this.dateFactory.fromPhrase(phrase)?.toISOString().split("T")[0];
336
373
  }
374
+ /**
375
+ * Returns the date and time of the day before yesterday
376
+ */
337
377
  get beforeYesterday() {
338
378
  return this.phraseMap.get("beforeYesterday");
339
379
  }
380
+ /**
381
+ * Returns the date and time of yesterday
382
+ */
340
383
  get yesterday() {
341
384
  return this.phraseMap.get("yesterday");
342
385
  }
386
+ /**
387
+ * Returns the date and time of today
388
+ */
343
389
  get today() {
344
390
  return this.phraseMap.get("today");
345
391
  }
392
+ /**
393
+ * Returns the date and time of tomorrow
394
+ */
346
395
  get tomorrow() {
347
396
  return this.phraseMap.get("tomorrow");
348
397
  }
398
+ /**
399
+ * Returns the date and time of the day after tomorrow
400
+ */
349
401
  get afterTomorrow() {
350
402
  return this.phraseMap.get("afterTomorrow");
351
403
  }
404
+ /**
405
+ * Returns the date and time of midnight today
406
+ */
352
407
  get midnight() {
353
408
  return this.phraseMap.get("midnight");
354
409
  }
410
+ /**
411
+ * Returns the date and time of today 1 week ago
412
+ */
355
413
  get lastWeek() {
356
414
  return this.phraseMap.get("lastWeek");
357
415
  }
416
+ /**
417
+ * Returns the date and time of today 1 week from now
418
+ */
358
419
  get nextWeek() {
359
420
  return this.phraseMap.get("nextWeek");
360
421
  }
422
+ /**
423
+ * Returns the date and time of today 1 fortnight ago
424
+ */
361
425
  get lastFortnight() {
362
426
  return this.phraseMap.get("lastFortnight");
363
427
  }
428
+ /**
429
+ * Returns the date and time of today 1 fortnight from now
430
+ */
364
431
  get nextFortnight() {
365
432
  return this.phraseMap.get("nextFortnight");
366
433
  }
@@ -374,48 +441,104 @@ var DatesObject = class {
374
441
  __privateAdd(this, _iso, new IsoDateFactory(__privateGet(this, _factory)));
375
442
  __privateAdd(this, _fmt, new FmtDateFactory(__privateGet(this, _factory)));
376
443
  }
444
+ /**
445
+ * Switches to the ISO factory, which offers an identical interface
446
+ * but returns ISO strings instead of Date objects.
447
+ *
448
+ * Example: `2020-01-01T00:00:00.000Z`
449
+ */
377
450
  get iso() {
378
451
  return __privateGet(this, _iso);
379
452
  }
453
+ /**
454
+ * Switches to the formatted factory, which offers an identical interface
455
+ * but returns formatted strings instead of Date objects.
456
+ *
457
+ * Example: `2020-01-01`
458
+ */
380
459
  get fmt() {
381
460
  return __privateGet(this, _fmt);
382
461
  }
462
+ /**
463
+ * Returns the current date and time.
464
+ */
383
465
  get now() {
384
466
  return __privateGet(this, _factory).find("now");
385
467
  }
468
+ /**
469
+ * Returns the date and time of the day before yesterday
470
+ */
386
471
  get beforeYesterday() {
387
472
  return __privateGet(this, _factory).find("beforeYesterday");
388
473
  }
474
+ /**
475
+ * Returns the date and time of yesterday
476
+ */
389
477
  get yesterday() {
390
478
  return __privateGet(this, _factory).find("yesterday");
391
479
  }
480
+ /**
481
+ * Returns the date and time of today
482
+ */
392
483
  get today() {
393
484
  return __privateGet(this, _factory).find("today");
394
485
  }
486
+ /**
487
+ * Returns the date and time of tomorrow
488
+ */
395
489
  get tomorrow() {
396
490
  return __privateGet(this, _factory).find("tomorrow");
397
491
  }
492
+ /**
493
+ * Returns the date and time of the day after tomorrow
494
+ */
398
495
  get afterTomorrow() {
399
496
  return __privateGet(this, _factory).find("afterTomorrow");
400
497
  }
498
+ /**
499
+ * Returns the date and time of midnight today
500
+ */
401
501
  get midnight() {
402
502
  return __privateGet(this, _factory).find("midnight");
403
503
  }
504
+ /**
505
+ * Returns the date and time of today 1 week ago
506
+ */
404
507
  get lastWeek() {
405
508
  return __privateGet(this, _factory).find("lastWeek");
406
509
  }
510
+ /**
511
+ * Returns the date and time of today 1 week from now
512
+ */
407
513
  get nextWeek() {
408
514
  return __privateGet(this, _factory).find("nextWeek");
409
515
  }
516
+ /**
517
+ * Returns the date and time of today 2 weeks ago
518
+ */
410
519
  get lastFortnight() {
411
520
  return __privateGet(this, _factory).find("lastFortnight");
412
521
  }
522
+ /**
523
+ * Returns the date and time of today 2 weeks from now
524
+ */
413
525
  get nextFortnight() {
414
526
  return __privateGet(this, _factory).find("nextFortnight");
415
527
  }
528
+ /**
529
+ * Attempts to parse a phrase into a date.
530
+ * @param phrase
531
+ * @returns
532
+ */
416
533
  fromPhrase(phrase) {
417
534
  return __privateGet(this, _factory).fromPhrase(phrase);
418
535
  }
536
+ /**
537
+ * Attempts to parse a phrase into a date.
538
+ * If the phrase is invalid, it will return an invalid date instead of throwing.
539
+ * @param phrase
540
+ * @returns
541
+ */
419
542
  fromPhraseSafe(phrase) {
420
543
  return __privateGet(this, _factory).fromPhraseSafe(phrase);
421
544
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/dates/date-factory.ts","../src/dates/midnight.ts","../src/dates/iso-date-factory.ts","../src/dates/formatted-date-factory.ts","../src/dates/dates.ts","../src/time/time.ts"],"sourcesContent":["export * from './dates'\nexport * from './time'","import { TimeUnit, camel, convertPhrase, collapse } from \"@autometa/phrases\";\nimport { midnight } from \"./midnight\";\nimport { AutomationError, raise } from \"@autometa/errors\";\nimport { ConfirmDefined, ConfirmLengthAtLeast } from \"@autometa/asserters\";\nimport { isValidDate, isValidISODateString, isValidTime, isValidYearMonth } from \"iso-datestring-validator\";\ntype TimeShortcut =\n | \"now\"\n | \"beforeYesterday\"\n | \"yesterday\"\n | \"today\"\n | \"tomorrow\"\n | \"afterTomorrow\"\n | \"midnight\"\n | \"lastWeek\"\n | \"nextWeek\"\n | \"lastFortnight\"\n | \"nextFortnight\";\n\nfunction isTimeShortcut(text: string): text is TimeShortcut {\n const converted = convertPhrase(text, camel);\n const includes = [\n \"now\",\n \"beforeYesterday\",\n \"yesterday\",\n \"today\",\n \"tomorrow\",\n \"afterTomorrow\",\n \"midnight\",\n \"lastWeek\",\n \"nextWeek\",\n \"lastFortnight\",\n \"nextFortnight\"\n ].includes(converted);\n if (!includes) {\n return false;\n }\n return true;\n}\nexport class DateFactory {\n phraseMap = new Map<TimeShortcut, () => Date>([\n [\"now\", () => this.make(0, \"days\")],\n [\"beforeYesterday\", () => this.make(-2, \"days\")],\n [\"yesterday\", () => this.make(-1, \"days\")],\n [\"today\", () => this.make(0, \"days\")],\n [\"tomorrow\", () => this.make(1, \"days\")],\n [\"afterTomorrow\", () => this.make(2, \"days\")],\n [\"nextWeek\", () => this.make(7, \"days\")],\n [\"lastWeek\", () => this.make(-7, \"days\")],\n [\"nextFortnight\", () => this.make(14, \"days\")],\n [\"lastFortnight\", () => this.make(-14, \"days\")],\n [\"midnight\", midnight]\n ]);\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n find(name: TimeShortcut): Date {\n const result = this.phraseMap.get(name);\n if (result) {\n return result();\n }\n raise(\n `Could not find date shortcut ${name}. Please use a valid date shortcut from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n\n fromPhraseSafe(phrase: string) {\n const name = convertPhrase(phrase, camel);\n if (isTimeShortcut(name)) {\n if (this.phraseMap.has(name)) {\n return this.phraseMap.get(name)?.call(this);\n }\n }\n \n const matchDay = this.#extractTimeFromPhrase(phrase);\n if (matchDay) {\n return matchDay;\n }\n const first = isValidDate(phrase);\n const second = isValidISODateString(phrase);\n const third = isValidTime(phrase);\n const fourth = isValidYearMonth(phrase);\n if (!first && !second && !third && !fourth) {\n return new Date(\"null\");\n }\n const parsed = new Date(phrase);\n if (isNaN(parsed.getTime())) {\n return new Date(Date.parse(phrase));\n }\n return parsed;\n }\n fromPhrase(phrase: string) {\n const result = this.fromPhraseSafe(phrase);\n if (result) {\n return result;\n }\n raise(\n `Could not parse date from phrase ${phrase}. Please use a valid date string or a phrase from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n make(timeOffset: number, timeunit: TimeUnit) {\n const unit = timeunit.endsWith(\"s\") ? timeunit : `${timeunit}s`;\n switch (unit) {\n case \"years\":\n return this.#addYears(timeOffset);\n case \"months\":\n return this.#addMonths(timeOffset);\n case \"weeks\":\n return this.#addWeeks(timeOffset);\n case \"days\":\n return this.#addDays(timeOffset);\n case \"seconds\":\n return this.#addSeconds(timeOffset);\n case \"milliseconds\":\n return this.#addMilliseconds(timeOffset);\n case \"hours\":\n return this.#addHours(timeOffset);\n case \"minutes\":\n return this.#addMinutes(timeOffset);\n default:\n throw new AutomationError(\n `Invalid timeunit ${timeunit}, options are 'days', 'seconds', 'milliseconds', 'hours', 'minutes'. Non plural equivalents such as 'day' or 'week' are also accepted.`\n );\n }\n }\n #extractTimeFromPhrase(phrase: string) {\n return (\n this.#extractFutureFromPhrase(phrase) ??\n this.#extractPastFromPhrase(phrase)\n );\n }\n #extractFutureFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)s? from now?/;\n const pastMatch = pastPattern.exec(phrase);\n\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, collapse) as TimeUnit;\n return this.make(Number(value), timeunit);\n }\n }\n #extractPastFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)(s)? ago?/gm;\n const pastMatch = pastPattern.exec(phrase);\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, camel) as TimeUnit;\n return this.make(-Number(value), timeunit);\n }\n }\n #addYears(yearsOffset: number) {\n const date = new Date();\n date.setFullYear(date.getFullYear() + yearsOffset);\n return date;\n }\n #addMonths(monthOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + monthOffset);\n return date;\n }\n #addWeeks(weekOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + weekOffset / 4);\n return date;\n }\n #addDays(daysOffset: number) {\n const date = new Date();\n date.setDate(date.getDate() + daysOffset);\n return date;\n }\n\n #addSeconds(secondsOffset: number) {\n const date = new Date();\n date.setSeconds(date.getSeconds() + secondsOffset);\n return date;\n }\n\n #addMilliseconds(millisecondsOffset: number) {\n const date = new Date();\n date.setMilliseconds(date.getMilliseconds() + millisecondsOffset);\n return date;\n }\n #addHours(hoursOffset: number) {\n const date = new Date();\n date.setHours(date.getHours() + hoursOffset);\n return date;\n }\n #addMinutes(minutesOffset: number) {\n const date = new Date();\n date.setMinutes(date.getMinutes() + minutesOffset);\n return date;\n }\n}\n","\nexport function midnight() {\n const date = new Date();\n date.setDate(date.getDate() + 1);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { midnight } from './midnight';\nimport { DateFactory } from './date-factory';\n\n\nexport class IsoDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory.make(daysOffset, timeunit).toISOString();\n }\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString();\n }\n\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n get today() {\n return this.phraseMap.get('today');\n }\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { DateFactory } from './date-factory';\nimport { midnight } from './midnight';\n\nexport class FmtDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory\n .make(daysOffset, timeunit)\n .toISOString()\n .split('T')[0];\n }\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString().split('T')[0];\n }\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n get today() {\n return this.phraseMap.get('today');\n }\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { DateFactory } from \"./date-factory\";\nimport { IsoDateFactory } from \"./iso-date-factory\";\nimport { FmtDateFactory } from \"./formatted-date-factory\";\nimport { TimeUnit } from \"@autometa/phrases\";\n\nexport class DatesObject {\n #factory: DateFactory = new DateFactory();\n #iso = new IsoDateFactory(this.#factory);\n #fmt = new FmtDateFactory(this.#factory);\n get iso() {\n return this.#iso;\n }\n\n get fmt() {\n return this.#fmt;\n }\n\n get now() {\n return this.#factory.find(\"now\");\n }\n\n get beforeYesterday(): Date {\n return this.#factory.find(\"beforeYesterday\");\n }\n\n get yesterday(): Date {\n return this.#factory.find(\"yesterday\");\n }\n\n get today(): Date {\n return this.#factory.find(\"today\");\n }\n\n get tomorrow(): Date {\n return this.#factory.find(\"tomorrow\");\n }\n\n get afterTomorrow(): Date {\n return this.#factory.find(\"afterTomorrow\");\n }\n\n get midnight(): Date {\n return this.#factory.find(\"midnight\");\n }\n\n get lastWeek(): Date {\n return this.#factory.find(\"lastWeek\");\n }\n\n get nextWeek(): Date {\n return this.#factory.find(\"nextWeek\");\n }\n\n get lastFortnight(): Date {\n return this.#factory.find(\"lastFortnight\");\n }\n\n get nextFortnight(): Date {\n return this.#factory.find(\"nextFortnight\");\n }\n\n fromPhrase(phrase: string) {\n return this.#factory.fromPhrase(phrase);\n }\n\n fromPhraseSafe(phrase: string) {\n return this.#factory.fromPhraseSafe(phrase);\n }\n\n make(timeOffset: number, timeUnit: TimeUnit) {\n return this.#factory.make(timeOffset, timeUnit);\n }\n}\n\nexport const Dates = new DatesObject();\n","import { AssertKey } from \"@autometa/asserters\";\nimport { convertPhrase, lower } from \"@autometa/phrases\";\ntype TimeDiffFn = (date1: Date, date2: Date) => number;\n\nexport class TimeDiff {\n minutes(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 60000;\n }\n seconds(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 1000;\n }\n millis(date1: Date, date2: Date) {\n const d1 = new Date(date1).getTime();\n const d2 = new Date(date2).getTime();\n return Math.abs(Math.round(d2 - d1));\n }\n days(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 86400000;\n }\n hours(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 3600000;\n }\n weeks(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 604800000;\n }\n fromPhrase(phrase: string): TimeDiffFn {\n const propertyKey = convertPhrase(phrase, lower);\n AssertKey(this, propertyKey);\n return (this[propertyKey] as TimeDiffFn).bind(this);\n }\n}\n\nexport class TimeObject {\n #diff = new TimeDiff();\n get diff() {\n return this.#diff;\n }\n}\n\nexport const Time = new TimeObject();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAyD;;;ACClD,SAAS,WAAW;AACzB,QAAM,OAAO,oBAAI,KAAK;AACtB,OAAK,QAAQ,KAAK,QAAQ,IAAI,CAAC;AAC/B,OAAK,SAAS,GAAG,GAAG,GAAG,CAAC;AACxB,SAAO;AACT;;;ADJA,oBAAuC;AACvC,uBAAqD;AACrD,sCAAiF;AAcjF,SAAS,eAAe,MAAoC;AAC1D,QAAM,gBAAY,8BAAc,MAAM,oBAAK;AAC3C,QAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,SAAS,SAAS;AACpB,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,SAAO;AACT;AArCA;AAsCO,IAAM,cAAN,MAAkB;AAAA,EAAlB;AAyFL;AAMA;AAUA;AASA;AAKA;AAKA;AAKA;AAMA;AAM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serters","import_phrases"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/dates/date-factory.ts","../src/dates/midnight.ts","../src/dates/iso-date-factory.ts","../src/dates/formatted-date-factory.ts","../src/dates/dates.ts","../src/time/time.ts"],"sourcesContent":["export * from './dates'\nexport * from './time'","import { TimeUnit, camel, convertPhrase, collapse } from \"@autometa/phrases\";\nimport { midnight } from \"./midnight\";\nimport { AutomationError, raise } from \"@autometa/errors\";\nimport { ConfirmDefined, ConfirmLengthAtLeast } from \"@autometa/asserters\";\nimport { isValidDate, isValidISODateString, isValidTime, isValidYearMonth } from \"iso-datestring-validator\";\ntype TimeShortcut =\n | \"now\"\n | \"beforeYesterday\"\n | \"yesterday\"\n | \"today\"\n | \"tomorrow\"\n | \"afterTomorrow\"\n | \"midnight\"\n | \"lastWeek\"\n | \"nextWeek\"\n | \"lastFortnight\"\n | \"nextFortnight\";\n\nfunction isTimeShortcut(text: string): text is TimeShortcut {\n const converted = convertPhrase(text, camel);\n const includes = [\n \"now\",\n \"beforeYesterday\",\n \"yesterday\",\n \"today\",\n \"tomorrow\",\n \"afterTomorrow\",\n \"midnight\",\n \"lastWeek\",\n \"nextWeek\",\n \"lastFortnight\",\n \"nextFortnight\"\n ].includes(converted);\n if (!includes) {\n return false;\n }\n return true;\n}\nexport class DateFactory {\n phraseMap = new Map<TimeShortcut, () => Date>([\n [\"now\", () => this.make(0, \"days\")],\n [\"beforeYesterday\", () => this.make(-2, \"days\")],\n [\"yesterday\", () => this.make(-1, \"days\")],\n [\"today\", () => this.make(0, \"days\")],\n [\"tomorrow\", () => this.make(1, \"days\")],\n [\"afterTomorrow\", () => this.make(2, \"days\")],\n [\"nextWeek\", () => this.make(7, \"days\")],\n [\"lastWeek\", () => this.make(-7, \"days\")],\n [\"nextFortnight\", () => this.make(14, \"days\")],\n [\"lastFortnight\", () => this.make(-14, \"days\")],\n [\"midnight\", midnight]\n ]);\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n find(name: TimeShortcut): Date {\n const result = this.phraseMap.get(name);\n if (result) {\n return result();\n }\n raise(\n `Could not find date shortcut ${name}. Please use a valid date shortcut from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n\n fromPhraseSafe(phrase: string) {\n const name = convertPhrase(phrase, camel);\n if (isTimeShortcut(name)) {\n if (this.phraseMap.has(name)) {\n return this.phraseMap.get(name)?.call(this);\n }\n }\n \n const matchDay = this.#extractTimeFromPhrase(phrase);\n if (matchDay) {\n return matchDay;\n }\n const first = isValidDate(phrase);\n const second = isValidISODateString(phrase);\n const third = isValidTime(phrase);\n const fourth = isValidYearMonth(phrase);\n if (!first && !second && !third && !fourth) {\n return new Date(\"null\");\n }\n const parsed = new Date(phrase);\n if (isNaN(parsed.getTime())) {\n return new Date(Date.parse(phrase));\n }\n return parsed;\n }\n fromPhrase(phrase: string) {\n const result = this.fromPhraseSafe(phrase);\n if (result) {\n return result;\n }\n raise(\n `Could not parse date from phrase ${phrase}. Please use a valid date string or a phrase from the following list: ${Array.from(\n this.phraseMap.keys()\n ).join(\", \")}`\n );\n }\n make(timeOffset: number, timeunit: TimeUnit) {\n const unit = timeunit.endsWith(\"s\") ? timeunit : `${timeunit}s`;\n switch (unit) {\n case \"years\":\n return this.#addYears(timeOffset);\n case \"months\":\n return this.#addMonths(timeOffset);\n case \"weeks\":\n return this.#addWeeks(timeOffset);\n case \"days\":\n return this.#addDays(timeOffset);\n case \"seconds\":\n return this.#addSeconds(timeOffset);\n case \"milliseconds\":\n return this.#addMilliseconds(timeOffset);\n case \"hours\":\n return this.#addHours(timeOffset);\n case \"minutes\":\n return this.#addMinutes(timeOffset);\n default:\n throw new AutomationError(\n `Invalid timeunit ${timeunit}, options are 'days', 'seconds', 'milliseconds', 'hours', 'minutes'. Non plural equivalents such as 'day' or 'week' are also accepted.`\n );\n }\n }\n #extractTimeFromPhrase(phrase: string) {\n return (\n this.#extractFutureFromPhrase(phrase) ??\n this.#extractPastFromPhrase(phrase)\n );\n }\n #extractFutureFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)s? from now?/;\n const pastMatch = pastPattern.exec(phrase);\n\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, collapse) as TimeUnit;\n return this.make(Number(value), timeunit);\n }\n }\n #extractPastFromPhrase(phrase: string) {\n const pastPattern = /^(\\d+) (.*)(s)? ago?/gm;\n const pastMatch = pastPattern.exec(phrase);\n if (ConfirmDefined(pastMatch) && ConfirmLengthAtLeast(pastMatch, 3)) {\n const [_, value, unit] = pastMatch;\n const timeunit = convertPhrase(unit, camel) as TimeUnit;\n return this.make(-Number(value), timeunit);\n }\n }\n #addYears(yearsOffset: number) {\n const date = new Date();\n date.setFullYear(date.getFullYear() + yearsOffset);\n return date;\n }\n #addMonths(monthOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + monthOffset);\n return date;\n }\n #addWeeks(weekOffset: number) {\n const date = new Date();\n date.setMonth(date.getMonth() + weekOffset / 4);\n return date;\n }\n #addDays(daysOffset: number) {\n const date = new Date();\n date.setDate(date.getDate() + daysOffset);\n return date;\n }\n\n #addSeconds(secondsOffset: number) {\n const date = new Date();\n date.setSeconds(date.getSeconds() + secondsOffset);\n return date;\n }\n\n #addMilliseconds(millisecondsOffset: number) {\n const date = new Date();\n date.setMilliseconds(date.getMilliseconds() + millisecondsOffset);\n return date;\n }\n #addHours(hoursOffset: number) {\n const date = new Date();\n date.setHours(date.getHours() + hoursOffset);\n return date;\n }\n #addMinutes(minutesOffset: number) {\n const date = new Date();\n date.setMinutes(date.getMinutes() + minutesOffset);\n return date;\n }\n}\n","\nexport function midnight() {\n const date = new Date();\n date.setDate(date.getDate() + 1);\n date.setHours(0, 0, 0, 0);\n return date;\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { midnight } from './midnight';\nimport { DateFactory } from './date-factory';\n\n\nexport class IsoDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory.make(daysOffset, timeunit).toISOString();\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * @param phrase\n * @returns\n */\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString();\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n\n /**\n * Returns the date and time of yesterday\n */\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n\n /**\n * Returns the date and time of today\n */\n get today() {\n return this.phraseMap.get('today');\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n\n /**\n * Returns the date and time of today 1 fortnight from now\n */\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { TimeUnit } from '@autometa/phrases';\nimport { DateFactory } from './date-factory';\nimport { midnight } from './midnight';\n\nexport class FmtDateFactory {\n constructor(readonly dateFactory: DateFactory) { }\n phraseMap = new Map<string, string>([\n ['beforeYesterday', this.make(-2, 'days')],\n ['yesterday', this.make(-1, 'days')],\n ['today', this.make(0, 'days')],\n ['tomorrow', this.make(1, 'days')],\n ['afterTomorrow', this.make(2, 'days')],\n ['nextWeek', this.make(7, 'days')],\n ['lastWeek', this.make(-7, 'days')],\n ['nextFortnight', this.make(14, 'days')],\n ['lastFortnight', this.make(-14, 'days')],\n ['midnight', midnight().toISOString()],\n ]);\n\n make(daysOffset: number, timeunit: TimeUnit) {\n return this.dateFactory\n .make(daysOffset, timeunit)\n .toISOString()\n .split('T')[0];\n }\n \n /**\n * Attempts to parse a phrase into a date.\n * @param phrase\n * @returns\n */\n fromPhrase(phrase: string) {\n return this.dateFactory.fromPhrase(phrase)?.toISOString().split('T')[0];\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday() {\n return this.phraseMap.get('beforeYesterday');\n }\n\n /**\n * Returns the date and time of yesterday\n */\n get yesterday() {\n return this.phraseMap.get('yesterday');\n }\n\n /**\n * Returns the date and time of today\n */\n get today() {\n return this.phraseMap.get('today');\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow() {\n return this.phraseMap.get('tomorrow');\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow() {\n return this.phraseMap.get('afterTomorrow');\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight() {\n return this.phraseMap.get('midnight');\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek() {\n return this.phraseMap.get('lastWeek');\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek() {\n return this.phraseMap.get('nextWeek');\n }\n\n /**\n * Returns the date and time of today 1 fortnight ago\n */\n get lastFortnight() {\n return this.phraseMap.get('lastFortnight');\n }\n\n /**\n * Returns the date and time of today 1 fortnight from now\n */\n get nextFortnight() {\n return this.phraseMap.get('nextFortnight');\n }\n}\n","import { DateFactory } from \"./date-factory\";\nimport { IsoDateFactory } from \"./iso-date-factory\";\nimport { FmtDateFactory } from \"./formatted-date-factory\";\nimport { TimeUnit } from \"@autometa/phrases\";\n\nexport class DatesObject {\n #factory: DateFactory = new DateFactory();\n #iso = new IsoDateFactory(this.#factory);\n #fmt = new FmtDateFactory(this.#factory);\n /**\n * Switches to the ISO factory, which offers an identical interface\n * but returns ISO strings instead of Date objects.\n * \n * Example: `2020-01-01T00:00:00.000Z`\n */\n get iso() {\n return this.#iso;\n }\n\n /**\n * Switches to the formatted factory, which offers an identical interface\n * but returns formatted strings instead of Date objects.\n * \n * Example: `2020-01-01`\n */\n get fmt() {\n return this.#fmt;\n }\n\n /**\n * Returns the current date and time.\n */\n get now() {\n return this.#factory.find(\"now\");\n }\n\n /**\n * Returns the date and time of the day before yesterday\n */\n get beforeYesterday(): Date {\n return this.#factory.find(\"beforeYesterday\");\n }\n \n /**\n * Returns the date and time of yesterday\n */\n get yesterday(): Date {\n return this.#factory.find(\"yesterday\");\n }\n\n /**\n * Returns the date and time of today\n */\n get today(): Date {\n return this.#factory.find(\"today\");\n }\n\n /**\n * Returns the date and time of tomorrow\n */\n get tomorrow(): Date {\n return this.#factory.find(\"tomorrow\");\n }\n\n /**\n * Returns the date and time of the day after tomorrow\n */\n get afterTomorrow(): Date {\n return this.#factory.find(\"afterTomorrow\");\n }\n\n /**\n * Returns the date and time of midnight today\n */\n get midnight(): Date {\n return this.#factory.find(\"midnight\");\n }\n\n /**\n * Returns the date and time of today 1 week ago\n */\n get lastWeek(): Date {\n return this.#factory.find(\"lastWeek\");\n }\n\n /**\n * Returns the date and time of today 1 week from now\n */\n get nextWeek(): Date {\n return this.#factory.find(\"nextWeek\");\n }\n\n /**\n * Returns the date and time of today 2 weeks ago\n */\n get lastFortnight(): Date {\n return this.#factory.find(\"lastFortnight\");\n }\n\n /**\n * Returns the date and time of today 2 weeks from now\n */\n get nextFortnight(): Date {\n return this.#factory.find(\"nextFortnight\");\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * @param phrase \n * @returns \n */\n fromPhrase(phrase: string) {\n return this.#factory.fromPhrase(phrase);\n }\n\n /**\n * Attempts to parse a phrase into a date.\n * If the phrase is invalid, it will return an invalid date instead of throwing.\n * @param phrase \n * @returns \n */\n fromPhraseSafe(phrase: string) {\n return this.#factory.fromPhraseSafe(phrase);\n }\n\n make(timeOffset: number, timeUnit: TimeUnit) {\n return this.#factory.make(timeOffset, timeUnit);\n }\n}\n\n/**\n * Date utility option to easily generate common\n * dates around the current date, like 'today', 'midnight',\n * 'tomorrow', 'nextWeek', etc.\n * \n * The Dates utility also supports certain language phrases\n * that might be natural in Cucumber's gherkin syntax, like\n * 'next week', 'last week', 'next fortnight', etc. as well\n * as more dynamic phrases like `1 day ago`, `2 weeks from now`,\n */\nexport const Dates = new DatesObject();\n","import { AssertKey } from \"@autometa/asserters\";\nimport { convertPhrase, lower } from \"@autometa/phrases\";\ntype TimeDiffFn = (date1: Date, date2: Date) => number;\n\nexport class TimeDiff {\n minutes(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 60000;\n }\n seconds(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 1000;\n }\n millis(date1: Date, date2: Date) {\n const d1 = new Date(date1).getTime();\n const d2 = new Date(date2).getTime();\n return Math.abs(Math.round(d2 - d1));\n }\n days(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 86400000;\n }\n hours(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 3600000;\n }\n weeks(date1: Date, date2: Date) {\n return this.millis(date1, date2) / 604800000;\n }\n fromPhrase(phrase: string): TimeDiffFn {\n const propertyKey = convertPhrase(phrase, lower);\n AssertKey(this, propertyKey);\n return (this[propertyKey] as TimeDiffFn).bind(this);\n }\n}\n\nexport class TimeObject {\n #diff = new TimeDiff();\n get diff() {\n return this.#diff;\n }\n}\n\nexport const Time = new TimeObject();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AA9BA;AAgCO,IAAM,aAAN,MAAiB;AAAA,EAAjB;AACL,8BAAQ,IAAI,SAAS;AAAA;AAAA,EACrB,IAAI,OAAO;AACT,WAAO,mBAAK;AAAA,EACd;AACF;AAJE;AAMK,IAAM,OAAO,IAAI,WAAW;","names":["import_asserters","import_phrases"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autometa/datetime",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Date and Time utilities for Autometa",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,9 +30,9 @@
30
30
  "vitest": "0.34.6"
31
31
  },
32
32
  "dependencies": {
33
- "@autometa/asserters": "^0.1.5",
33
+ "@autometa/asserters": "^0.1.6",
34
34
  "@autometa/errors": "^0.2.0",
35
- "@autometa/phrases": "^0.1.9",
35
+ "@autometa/phrases": "^0.1.10",
36
36
  "iso-datestring-validator": "^2.2.2"
37
37
  },
38
38
  "scripts": {