date-vir 8.3.2 → 8.4.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.
@@ -15,6 +15,8 @@ import { type FullDate } from './full-date-shape.js';
15
15
  * createFullDateInUserTimezone(new Date());
16
16
  * createFullDateInUserTimezone(112300120);
17
17
  * ```
18
+ *
19
+ * @throws Error: if a valid date cannot be created.
18
20
  */
19
21
  export declare function createFullDateInUserTimezone(dateLike: Readonly<DateLike>): FullDate;
20
22
  /**
@@ -31,6 +33,8 @@ export declare function createFullDateInUserTimezone(dateLike: Readonly<DateLike
31
33
  * createUtcFullDate(new Date());
32
34
  * createUtcFullDate(112300120);
33
35
  * ```
36
+ *
37
+ * @throws Error: if a valid date cannot be created.
34
38
  */
35
39
  export declare function createUtcFullDate(dateLike: Readonly<DateLike>): FullDate<UtcTimezone>;
36
40
  /**
@@ -47,6 +51,8 @@ export declare function createUtcFullDate(dateLike: Readonly<DateLike>): FullDat
47
51
  * createFullDate(new Date(), timezones['Australia/Brisbane']);
48
52
  * createFullDate(112300120, timezones['Etc/GMT-11']);
49
53
  * ```
54
+ *
55
+ * @throws Error: if a valid date cannot be created.
50
56
  */
51
57
  export declare function createFullDate<const SpecificTimezone extends Timezone>(
52
58
  /** The original date representation to be converted into a FullDate. */
@@ -19,6 +19,8 @@ import { parseDateString } from './string-parsing.js';
19
19
  * createFullDateInUserTimezone(new Date());
20
20
  * createFullDateInUserTimezone(112300120);
21
21
  * ```
22
+ *
23
+ * @throws Error: if a valid date cannot be created.
22
24
  */
23
25
  export function createFullDateInUserTimezone(dateLike) {
24
26
  return createFullDate(dateLike, userTimezone);
@@ -37,6 +39,8 @@ export function createFullDateInUserTimezone(dateLike) {
37
39
  * createUtcFullDate(new Date());
38
40
  * createUtcFullDate(112300120);
39
41
  * ```
42
+ *
43
+ * @throws Error: if a valid date cannot be created.
40
44
  */
41
45
  export function createUtcFullDate(dateLike) {
42
46
  return createFullDate(dateLike, utcTimezone);
@@ -55,6 +59,8 @@ export function createUtcFullDate(dateLike) {
55
59
  * createFullDate(new Date(), timezones['Australia/Brisbane']);
56
60
  * createFullDate(112300120, timezones['Etc/GMT-11']);
57
61
  * ```
62
+ *
63
+ * @throws Error: if a valid date cannot be created.
58
64
  */
59
65
  export function createFullDate(
60
66
  /** The original date representation to be converted into a FullDate. */
@@ -0,0 +1,13 @@
1
+ import { type Timezone } from '../timezone/timezones.js';
2
+ import { type DateLike } from './date-like.js';
3
+ import { type FullDate } from './full-date-shape.js';
4
+ /**
5
+ * Parses the given {@link DateLike} and converts it into a {@link FullDate} instance with the given
6
+ * timezone. If the conversion fails or the input {@link DateLike} is empty, `undefined` is
7
+ * returned.
8
+ */
9
+ export declare function maybeCreateFullDate<const SpecificTimezone extends Timezone>(
10
+ /** The original date representation to be converted into a FullDate. */
11
+ dateLike: Readonly<DateLike> | undefined | null,
12
+ /** The timezone that this date/time is meant for / originated from. */
13
+ timezone: SpecificTimezone): FullDate<SpecificTimezone> | undefined;
@@ -0,0 +1,21 @@
1
+ import { createFullDate } from './create-full-date.js';
2
+ /**
3
+ * Parses the given {@link DateLike} and converts it into a {@link FullDate} instance with the given
4
+ * timezone. If the conversion fails or the input {@link DateLike} is empty, `undefined` is
5
+ * returned.
6
+ */
7
+ export function maybeCreateFullDate(
8
+ /** The original date representation to be converted into a FullDate. */
9
+ dateLike,
10
+ /** The timezone that this date/time is meant for / originated from. */
11
+ timezone) {
12
+ if (!dateLike) {
13
+ return undefined;
14
+ }
15
+ try {
16
+ return createFullDate(dateLike, timezone);
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export * from './full-date/full-date-parts.js';
22
22
  export * from './full-date/full-date-shape.js';
23
23
  export * from './full-date/is-valid-full-date.js';
24
24
  export * from './full-date/luxon-date-time-conversion.js';
25
+ export * from './full-date/maybe-create-date.js';
25
26
  export * from './full-date/parsing.js';
26
27
  export * from './timezone/timezone-checks.js';
27
28
  export * from './timezone/timezone-names.js';
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ export * from './full-date/full-date-parts.js';
22
22
  export * from './full-date/full-date-shape.js';
23
23
  export * from './full-date/is-valid-full-date.js';
24
24
  export * from './full-date/luxon-date-time-conversion.js';
25
+ export * from './full-date/maybe-create-date.js';
25
26
  export * from './full-date/parsing.js';
26
27
  export * from './timezone/timezone-checks.js';
27
28
  export * from './timezone/timezone-names.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-vir",
3
- "version": "8.3.2",
3
+ "version": "8.4.0",
4
4
  "description": "Easy and explicit dates and times.",
5
5
  "keywords": [
6
6
  "date",
@@ -17,7 +17,7 @@
17
17
  "type": "git",
18
18
  "url": "git+https://github.com/electrovir/date-vir.git"
19
19
  },
20
- "license": "(MIT or CC0 1.0)",
20
+ "license": "(MIT OR CC0-1.0)",
21
21
  "author": {
22
22
  "name": "electrovir",
23
23
  "url": "https://github.com/electrovir"
@@ -34,25 +34,25 @@
34
34
  "test:docs": "virmator docs check"
35
35
  },
36
36
  "dependencies": {
37
- "@augment-vir/assert": "^31.68.4",
37
+ "@augment-vir/assert": "^31.69.0",
38
38
  "@augment-vir/common": "^31.68.4",
39
- "@date-vir/duration": "^8.3.2",
39
+ "@date-vir/duration": "^8.4.0",
40
40
  "@types/luxon": "^3.7.1",
41
41
  "luxon": "^3.7.2",
42
- "object-shape-tester": "^6.11.0",
42
+ "object-shape-tester": "^6.13.0",
43
43
  "type-fest": "^5.5.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@augment-vir/test": "^31.68.4",
46
+ "@augment-vir/test": "^31.69.0",
47
47
  "@web/dev-server-esbuild": "^1.0.5",
48
48
  "@web/test-runner": "^0.20.2",
49
49
  "@web/test-runner-commands": "^0.9.0",
50
50
  "@web/test-runner-playwright": "^0.11.1",
51
51
  "@web/test-runner-visual-regression": "^0.10.0",
52
- "element-vir": "^26.15.1",
52
+ "element-vir": "^26.17.0",
53
53
  "istanbul-smart-text-reporter": "^1.1.5",
54
- "markdown-code-example-inserter": "^3.0.3",
55
- "typedoc": "^0.28.18",
54
+ "markdown-code-example-inserter": "^3.0.5",
55
+ "typedoc": "^0.28.19",
56
56
  "typescript": "^5.9.3"
57
57
  },
58
58
  "engines": {