date-vir 0.1.1 → 0.2.1

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/README.md CHANGED
@@ -75,7 +75,7 @@ parseStrangeString({
75
75
 
76
76
  ```TypeScript
77
77
  import {
78
- HtmlInputElementTypeEnum,
78
+ FullDatePartEnum,
79
79
  createFullDate,
80
80
  formatPresets,
81
81
  timezones,
@@ -111,7 +111,7 @@ toLocaleString(myFullDate, formatPresets.DatetimeFull); // returns 'June 5, 2023
111
111
  * Formats the given FullDate to a string so that it is ready to be assigned to the value attribute
112
112
  * of an <input type="date" /> element.
113
113
  */
114
- toHtmlInputString(myFullDate, HtmlInputElementTypeEnum.Date); // returns '2023-06-05'
114
+ toHtmlInputString(myFullDate, FullDatePartEnum.Date); // returns '2023-06-05'
115
115
  ```
116
116
 
117
117
  # Timezone
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combineDateParts = void 0;
4
+ const full_date_shape_1 = require("./full-date-shape");
5
+ function combineDateParts(maybeDateParts) {
6
+ const timePart = maybeDateParts.time
7
+ ? {
8
+ hour: maybeDateParts.time.hour,
9
+ minute: maybeDateParts.time.minute,
10
+ second: maybeDateParts.time.second,
11
+ millisecond: maybeDateParts.time.millisecond,
12
+ timezone: maybeDateParts.time.timezone,
13
+ }
14
+ : undefined;
15
+ const datePart = maybeDateParts.date
16
+ ? {
17
+ year: maybeDateParts.date.year,
18
+ month: maybeDateParts.date.month,
19
+ day: maybeDateParts.date.day,
20
+ timezone: maybeDateParts.date.timezone,
21
+ }
22
+ : undefined;
23
+ if (timePart && datePart) {
24
+ if (timePart.timezone !== datePart.timezone) {
25
+ throw new Error(`Time and date parts have mismatching timezones. Got '${timePart.timezone}' and '${datePart.timezone}'.`);
26
+ }
27
+ return {
28
+ ...timePart,
29
+ ...datePart,
30
+ };
31
+ }
32
+ if (timePart) {
33
+ return timePart;
34
+ }
35
+ if (datePart) {
36
+ return datePart;
37
+ }
38
+ return undefined;
39
+ }
40
+ exports.combineDateParts = combineDateParts;
@@ -35,6 +35,9 @@ exports.createFullDate = createFullDate;
35
35
  * but represented in a new timezone.
36
36
  */
37
37
  function toNewTimezone(fullDate, timezone) {
38
+ if (fullDate.timezone === timezone) {
39
+ return fullDate;
40
+ }
38
41
  return createFullDate(fullDate, timezone);
39
42
  }
40
43
  exports.toNewTimezone = toNewTimezone;
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = void 0;
3
+ exports.fullDateShape = exports.datePartShape = exports.timePartShape = exports.FullDatePartEnum = void 0;
4
4
  const object_shape_tester_1 = require("object-shape-tester");
5
5
  const timezones_1 = require("../timezone/timezones");
6
- exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
6
+ var FullDatePartEnum;
7
+ (function (FullDatePartEnum) {
8
+ FullDatePartEnum["Date"] = "date";
9
+ FullDatePartEnum["Time"] = "time";
10
+ })(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
11
+ exports.timePartShape = (0, object_shape_tester_1.defineShape)({
7
12
  /** Hour of the day in 24 time: 0-23 */
8
13
  hour: 14,
9
14
  /** Minute of the hour: 0-59 */
@@ -15,7 +20,7 @@ exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
15
20
  /** The timezone that this date/time is meant for / originated from. */
16
21
  timezone: timezones_1.utcTimezone,
17
22
  });
18
- exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
23
+ exports.datePartShape = (0, object_shape_tester_1.defineShape)({
19
24
  /**
20
25
  * The full, four digit year.
21
26
  *
@@ -30,4 +35,4 @@ exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
30
35
  /** The timezone that this date/time is meant for / originated from. */
31
36
  timezone: timezones_1.utcTimezone,
32
37
  });
33
- exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.dateOnlyShape, exports.timeOnlyShape));
38
+ exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.datePartShape, exports.timePartShape));
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHtmlInputString = exports.HtmlInputElementTypeEnum = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
3
+ exports.toHtmlInputString = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
4
4
  const common_1 = require("@augment-vir/common");
5
5
  const locales_1 = require("../locales");
6
6
  const timezones_1 = require("../timezone/timezones");
7
+ const full_date_shape_1 = require("./full-date-shape");
7
8
  const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
8
9
  /** Convert a FullDate into a unix timestamp with milliseconds. */
9
10
  function toTimestamp(fullDate) {
@@ -41,17 +42,17 @@ function toFormattedString(fullDate, format, localeOverride = locales_1.userLoca
41
42
  return (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toFormat(format, { locale: localeOverride });
42
43
  }
43
44
  exports.toFormattedString = toFormattedString;
44
- /**
45
- * The different options for the "type" attribute in an <input> element that require specific
46
- * formatting relevant to dates.
47
- */
48
- var HtmlInputElementTypeEnum;
49
- (function (HtmlInputElementTypeEnum) {
50
- HtmlInputElementTypeEnum["Date"] = "date";
51
- HtmlInputElementTypeEnum["Time"] = "time";
52
- })(HtmlInputElementTypeEnum = exports.HtmlInputElementTypeEnum || (exports.HtmlInputElementTypeEnum = {}));
53
45
  function toHtmlInputString(fullDate, inputType, includeSeconds) {
54
- if (inputType === HtmlInputElementTypeEnum.Date) {
46
+ if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
47
+ if (fullDate.year == undefined) {
48
+ throw new Error(`Tried to create date string but no year was provided.`);
49
+ }
50
+ if (fullDate.month == undefined) {
51
+ throw new Error(`Tried to create date string but no month was provided.`);
52
+ }
53
+ if (fullDate.day == undefined) {
54
+ throw new Error(`Tried to create date string but no day was provided.`);
55
+ }
55
56
  const dateParts = [
56
57
  fullDate.year,
57
58
  String(fullDate.month).padStart(2, '0'),
@@ -59,7 +60,16 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
59
60
  ];
60
61
  return dateParts.join('-');
61
62
  }
62
- else if (inputType === HtmlInputElementTypeEnum.Time) {
63
+ else if (inputType === full_date_shape_1.FullDatePartEnum.Time) {
64
+ if (includeSeconds && fullDate.second == undefined) {
65
+ throw new Error('Tried to include seconds in the time string but no seconds were provided.');
66
+ }
67
+ if (fullDate.hour == undefined) {
68
+ throw new Error(`Tried to create time string but no hour was provided.`);
69
+ }
70
+ if (fullDate.minute == undefined) {
71
+ throw new Error(`Tried to create time string but no minutes were provided.`);
72
+ }
63
73
  const timeParts = [
64
74
  String(fullDate.hour).padStart(2, '0'),
65
75
  String(fullDate.minute).padStart(2, '0'),
@@ -68,7 +78,7 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
68
78
  return timeParts.join(':');
69
79
  }
70
80
  else {
71
- throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of HtmlInputElementTypeEnum or one of ${(0, common_1.getEnumTypedValues)(HtmlInputElementTypeEnum).join(', ')}.`);
81
+ throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${(0, common_1.getEnumTypedValues)(full_date_shape_1.FullDatePartEnum).join(', ')}.`);
72
82
  }
73
83
  }
74
84
  exports.toHtmlInputString = toHtmlInputString;
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./full-date/calculate-relative-date"), exports);
18
+ __exportStar(require("./full-date/combine-dates"), exports);
17
19
  __exportStar(require("./full-date/create-full-date"), exports);
18
20
  __exportStar(require("./full-date/date-like"), exports);
19
21
  __exportStar(require("./full-date/format-presets"), exports);
@@ -0,0 +1,37 @@
1
+ import { DatePart, FullDate, FullDatePartEnum, TimePart } from './full-date-shape';
2
+ type MaybeDateParts = Partial<{
3
+ [FullDatePartEnum.Date]: DatePart | undefined;
4
+ [FullDatePartEnum.Time]: TimePart | undefined;
5
+ }>;
6
+ export type MaybeDatePart = FullDate | DatePart | TimePart | undefined;
7
+ /**
8
+ * Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezones must
9
+ * match for both inputs. If two complete FullDate objects are passed in, only the respective parts
10
+ * of each is used.
11
+ */
12
+ export declare function combineDateParts(maybeDateParts: {
13
+ [FullDatePartEnum.Date]: DatePart;
14
+ [FullDatePartEnum.Time]: TimePart;
15
+ }): FullDate;
16
+ export declare function combineDateParts(maybeDateParts: {
17
+ [FullDatePartEnum.Date]?: undefined;
18
+ [FullDatePartEnum.Time]?: undefined;
19
+ }): undefined;
20
+ export declare function combineDateParts(maybeDateParts: {
21
+ [FullDatePartEnum.Date]: DatePart;
22
+ [FullDatePartEnum.Time]?: undefined;
23
+ }): DatePart;
24
+ export declare function combineDateParts(maybeDateParts: {
25
+ [FullDatePartEnum.Date]: DatePart;
26
+ [FullDatePartEnum.Time]?: TimePart | undefined;
27
+ }): FullDate | DatePart;
28
+ export declare function combineDateParts(maybeDateParts: {
29
+ [FullDatePartEnum.Date]?: undefined;
30
+ [FullDatePartEnum.Time]: TimePart;
31
+ }): TimePart;
32
+ export declare function combineDateParts(maybeDateParts: {
33
+ [FullDatePartEnum.Date]?: DatePart | undefined;
34
+ [FullDatePartEnum.Time]: TimePart;
35
+ }): FullDate | TimePart;
36
+ export declare function combineDateParts(maybeDateParts: MaybeDateParts): MaybeDatePart;
37
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combineDateParts = void 0;
4
+ const full_date_shape_1 = require("./full-date-shape");
5
+ function combineDateParts(maybeDateParts) {
6
+ const timePart = maybeDateParts.time
7
+ ? {
8
+ hour: maybeDateParts.time.hour,
9
+ minute: maybeDateParts.time.minute,
10
+ second: maybeDateParts.time.second,
11
+ millisecond: maybeDateParts.time.millisecond,
12
+ timezone: maybeDateParts.time.timezone,
13
+ }
14
+ : undefined;
15
+ const datePart = maybeDateParts.date
16
+ ? {
17
+ year: maybeDateParts.date.year,
18
+ month: maybeDateParts.date.month,
19
+ day: maybeDateParts.date.day,
20
+ timezone: maybeDateParts.date.timezone,
21
+ }
22
+ : undefined;
23
+ if (timePart && datePart) {
24
+ if (timePart.timezone !== datePart.timezone) {
25
+ throw new Error(`Time and date parts have mismatching timezones. Got '${timePart.timezone}' and '${datePart.timezone}'.`);
26
+ }
27
+ return {
28
+ ...timePart,
29
+ ...datePart,
30
+ };
31
+ }
32
+ if (timePart) {
33
+ return timePart;
34
+ }
35
+ if (datePart) {
36
+ return datePart;
37
+ }
38
+ return undefined;
39
+ }
40
+ exports.combineDateParts = combineDateParts;
@@ -35,6 +35,9 @@ exports.createFullDate = createFullDate;
35
35
  * but represented in a new timezone.
36
36
  */
37
37
  function toNewTimezone(fullDate, timezone) {
38
+ if (fullDate.timezone === timezone) {
39
+ return fullDate;
40
+ }
38
41
  return createFullDate(fullDate, timezone);
39
42
  }
40
43
  exports.toNewTimezone = toNewTimezone;
@@ -1,9 +1,10 @@
1
- import { Overwrite } from '@augment-vir/common';
1
+ import { Overwrite, RequiredBy } from '@augment-vir/common';
2
2
  import { Timezone } from '../timezone/timezone-names';
3
- export type WithTimezone = {
4
- timezone: Timezone;
5
- };
6
- export declare const timeOnlyShape: import("object-shape-tester").ShapeDefinition<{
3
+ export declare enum FullDatePartEnum {
4
+ Date = "date",
5
+ Time = "time"
6
+ }
7
+ export declare const timePartShape: import("object-shape-tester").ShapeDefinition<{
7
8
  /** Hour of the day in 24 time: 0-23 */
8
9
  hour: number;
9
10
  /** Minute of the hour: 0-59 */
@@ -15,8 +16,8 @@ export declare const timeOnlyShape: import("object-shape-tester").ShapeDefinitio
15
16
  /** The timezone that this date/time is meant for / originated from. */
16
17
  timezone: "UTC";
17
18
  }>;
18
- export type TimeOnly = Overwrite<(typeof timeOnlyShape)['runTimeType'], WithTimezone>;
19
- export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinition<{
19
+ export type TimePart = RequiredBy<Partial<FullDate>, keyof (typeof timePartShape)['runTimeType']>;
20
+ export declare const datePartShape: import("object-shape-tester").ShapeDefinition<{
20
21
  /**
21
22
  * The full, four digit year.
22
23
  *
@@ -31,7 +32,7 @@ export declare const dateOnlyShape: import("object-shape-tester").ShapeDefinitio
31
32
  /** The timezone that this date/time is meant for / originated from. */
32
33
  timezone: "UTC";
33
34
  }>;
34
- export type DateOnly = Overwrite<(typeof dateOnlyShape)['runTimeType'], WithTimezone>;
35
+ export type DatePart = RequiredBy<Partial<FullDate>, keyof (typeof datePartShape)['runTimeType']>;
35
36
  export declare const fullDateShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
36
37
  /**
37
38
  * The full, four digit year.
@@ -62,4 +63,6 @@ export declare const fullDateShape: import("object-shape-tester").ShapeDefinitio
62
63
  * A easily serializable (it fits into plain JSON) object that completely defines how a date is to
63
64
  * be represented with minimal data.
64
65
  */
65
- export type FullDate = Overwrite<(typeof fullDateShape)['runTimeType'], WithTimezone>;
66
+ export type FullDate = Overwrite<(typeof fullDateShape)['runTimeType'], {
67
+ timezone: Timezone;
68
+ }>;
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fullDateShape = exports.dateOnlyShape = exports.timeOnlyShape = void 0;
3
+ exports.fullDateShape = exports.datePartShape = exports.timePartShape = exports.FullDatePartEnum = void 0;
4
4
  const object_shape_tester_1 = require("object-shape-tester");
5
5
  const timezones_1 = require("../timezone/timezones");
6
- exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
6
+ var FullDatePartEnum;
7
+ (function (FullDatePartEnum) {
8
+ FullDatePartEnum["Date"] = "date";
9
+ FullDatePartEnum["Time"] = "time";
10
+ })(FullDatePartEnum = exports.FullDatePartEnum || (exports.FullDatePartEnum = {}));
11
+ exports.timePartShape = (0, object_shape_tester_1.defineShape)({
7
12
  /** Hour of the day in 24 time: 0-23 */
8
13
  hour: 14,
9
14
  /** Minute of the hour: 0-59 */
@@ -15,7 +20,7 @@ exports.timeOnlyShape = (0, object_shape_tester_1.defineShape)({
15
20
  /** The timezone that this date/time is meant for / originated from. */
16
21
  timezone: timezones_1.utcTimezone,
17
22
  });
18
- exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
23
+ exports.datePartShape = (0, object_shape_tester_1.defineShape)({
19
24
  /**
20
25
  * The full, four digit year.
21
26
  *
@@ -30,4 +35,4 @@ exports.dateOnlyShape = (0, object_shape_tester_1.defineShape)({
30
35
  /** The timezone that this date/time is meant for / originated from. */
31
36
  timezone: timezones_1.utcTimezone,
32
37
  });
33
- exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.dateOnlyShape, exports.timeOnlyShape));
38
+ exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.datePartShape, exports.timePartShape));
@@ -1,5 +1,6 @@
1
- import { PartialAndUndefined } from '@augment-vir/common';
2
- import { FullDate } from './full-date-shape';
1
+ import { PartialAndUndefined, RequiredBy } from '@augment-vir/common';
2
+ import { SetOptional } from 'type-fest';
3
+ import { DatePart, FullDate, FullDatePartEnum } from './full-date-shape';
3
4
  import { JustDateString, JustTimeString, JustTimeWithSecondsString, UtcIsoString } from './string-format-types';
4
5
  /** Convert a FullDate into a unix timestamp with milliseconds. */
5
6
  export declare function toTimestamp(fullDate: FullDate): number;
@@ -17,26 +18,22 @@ export declare function toLocaleString(fullDate: FullDate, formatOptions?: (Intl
17
18
  * already has many formatting options.
18
19
  */
19
20
  export declare function toFormattedString(fullDate: FullDate, format: string, localeOverride?: string): string;
20
- /**
21
- * The different options for the "type" attribute in an <input> element that require specific
22
- * formatting relevant to dates.
23
- */
24
- export declare enum HtmlInputElementTypeEnum {
25
- Date = "date",
26
- Time = "time"
27
- }
21
+ type OnlyDatePart = SetOptional<DatePart, 'timezone'>;
22
+ type HourMinutePart = RequiredBy<Partial<FullDate>, 'hour' | 'minute'>;
23
+ type HourMinuteSecondPart = RequiredBy<Partial<FullDate>, 'hour' | 'minute' | 'second'>;
28
24
  /**
29
25
  * Converts a FullDate object into a string that is understood by type="date" or type="time"
30
26
  * HTMLInputElement instances. Can optionally include seconds as well for type="time".
31
27
  *
32
- * This does NO timezone operations, the literal stored date and time are simply concatenated into a
33
- * string. If you wish to convert time zones, first call createFullDate and give it a different time
34
- * zone.
28
+ * This function ignores the timezone, the literal stored date and time numbers are simply
29
+ * concatenated into a string. If you wish to convert time zones, first call toNewTimezone on your
30
+ * FullDate object.
35
31
  */
36
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum.Date): JustDateString;
37
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum.Time, includeSeconds?: false | undefined): JustTimeString;
38
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum.Time, includeSeconds: true): JustTimeWithSecondsString;
39
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum.Time, includeSeconds?: boolean | undefined): JustTimeWithSecondsString | JustTimeString;
40
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum, includeSeconds: true): JustDateString | JustTimeWithSecondsString;
41
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum, includeSeconds?: false | undefined): JustDateString | JustTimeString;
42
- export declare function toHtmlInputString(fullDate: FullDate, inputType: HtmlInputElementTypeEnum, includeSeconds?: boolean | undefined): JustDateString | JustTimeWithSecondsString | JustTimeString;
32
+ export declare function toHtmlInputString(fullDate: OnlyDatePart, inputType: FullDatePartEnum.Date): JustDateString;
33
+ export declare function toHtmlInputString(fullDate: HourMinutePart, inputType: FullDatePartEnum.Time, includeSeconds?: false | undefined): JustTimeString;
34
+ export declare function toHtmlInputString(fullDate: HourMinuteSecondPart, inputType: FullDatePartEnum.Time, includeSeconds: true): JustTimeWithSecondsString;
35
+ export declare function toHtmlInputString(fullDate: HourMinutePart | HourMinuteSecondPart, inputType: FullDatePartEnum.Time, includeSeconds?: boolean | undefined): JustTimeWithSecondsString | JustTimeString;
36
+ export declare function toHtmlInputString(fullDate: HourMinuteSecondPart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds: true): JustDateString | JustTimeWithSecondsString;
37
+ export declare function toHtmlInputString(fullDate: HourMinutePart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds?: false | undefined): JustDateString | JustTimeString;
38
+ export declare function toHtmlInputString(fullDate: HourMinutePart | HourMinuteSecondPart | OnlyDatePart, inputType: FullDatePartEnum, includeSeconds?: boolean | undefined): JustDateString | JustTimeWithSecondsString | JustTimeString;
39
+ export {};
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHtmlInputString = exports.HtmlInputElementTypeEnum = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
3
+ exports.toHtmlInputString = exports.toFormattedString = exports.toLocaleString = exports.toIsoString = exports.toTimestamp = void 0;
4
4
  const common_1 = require("@augment-vir/common");
5
5
  const locales_1 = require("../locales");
6
6
  const timezones_1 = require("../timezone/timezones");
7
+ const full_date_shape_1 = require("./full-date-shape");
7
8
  const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
8
9
  /** Convert a FullDate into a unix timestamp with milliseconds. */
9
10
  function toTimestamp(fullDate) {
@@ -41,17 +42,17 @@ function toFormattedString(fullDate, format, localeOverride = locales_1.userLoca
41
42
  return (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toFormat(format, { locale: localeOverride });
42
43
  }
43
44
  exports.toFormattedString = toFormattedString;
44
- /**
45
- * The different options for the "type" attribute in an <input> element that require specific
46
- * formatting relevant to dates.
47
- */
48
- var HtmlInputElementTypeEnum;
49
- (function (HtmlInputElementTypeEnum) {
50
- HtmlInputElementTypeEnum["Date"] = "date";
51
- HtmlInputElementTypeEnum["Time"] = "time";
52
- })(HtmlInputElementTypeEnum = exports.HtmlInputElementTypeEnum || (exports.HtmlInputElementTypeEnum = {}));
53
45
  function toHtmlInputString(fullDate, inputType, includeSeconds) {
54
- if (inputType === HtmlInputElementTypeEnum.Date) {
46
+ if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
47
+ if (fullDate.year == undefined) {
48
+ throw new Error(`Tried to create date string but no year was provided.`);
49
+ }
50
+ if (fullDate.month == undefined) {
51
+ throw new Error(`Tried to create date string but no month was provided.`);
52
+ }
53
+ if (fullDate.day == undefined) {
54
+ throw new Error(`Tried to create date string but no day was provided.`);
55
+ }
55
56
  const dateParts = [
56
57
  fullDate.year,
57
58
  String(fullDate.month).padStart(2, '0'),
@@ -59,7 +60,16 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
59
60
  ];
60
61
  return dateParts.join('-');
61
62
  }
62
- else if (inputType === HtmlInputElementTypeEnum.Time) {
63
+ else if (inputType === full_date_shape_1.FullDatePartEnum.Time) {
64
+ if (includeSeconds && fullDate.second == undefined) {
65
+ throw new Error('Tried to include seconds in the time string but no seconds were provided.');
66
+ }
67
+ if (fullDate.hour == undefined) {
68
+ throw new Error(`Tried to create time string but no hour was provided.`);
69
+ }
70
+ if (fullDate.minute == undefined) {
71
+ throw new Error(`Tried to create time string but no minutes were provided.`);
72
+ }
63
73
  const timeParts = [
64
74
  String(fullDate.hour).padStart(2, '0'),
65
75
  String(fullDate.minute).padStart(2, '0'),
@@ -68,7 +78,7 @@ function toHtmlInputString(fullDate, inputType, includeSeconds) {
68
78
  return timeParts.join(':');
69
79
  }
70
80
  else {
71
- throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of HtmlInputElementTypeEnum or one of ${(0, common_1.getEnumTypedValues)(HtmlInputElementTypeEnum).join(', ')}.`);
81
+ throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${(0, common_1.getEnumTypedValues)(full_date_shape_1.FullDatePartEnum).join(', ')}.`);
72
82
  }
73
83
  }
74
84
  exports.toHtmlInputString = toHtmlInputString;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './full-date/calculate-relative-date';
2
+ export * from './full-date/combine-dates';
1
3
  export * from './full-date/create-full-date';
2
4
  export * from './full-date/date-like';
3
5
  export * from './full-date/format-presets';
package/dist/index.js CHANGED
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./full-date/calculate-relative-date"), exports);
18
+ __exportStar(require("./full-date/combine-dates"), exports);
17
19
  __exportStar(require("./full-date/create-full-date"), exports);
18
20
  __exportStar(require("./full-date/date-like"), exports);
19
21
  __exportStar(require("./full-date/format-presets"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-vir",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Easy and explicit dates and times",
5
5
  "keywords": [
6
6
  "date",
@@ -42,7 +42,8 @@
42
42
  "@augment-vir/common": "^14.2.2",
43
43
  "@types/luxon": "^3.3.0",
44
44
  "luxon": "^3.3.0",
45
- "object-shape-tester": "^0.2.7"
45
+ "object-shape-tester": "^0.2.7",
46
+ "type-fest": "^3.11.1"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@augment-vir/browser-testing": "^14.2.2",
@@ -55,7 +56,7 @@
55
56
  "@web/test-runner-playwright": "^0.10.0",
56
57
  "@web/test-runner-visual-regression": "^0.8.0",
57
58
  "cspell": "^6.31.1",
58
- "element-vir": "^13.0.2",
59
+ "element-vir": "^13.0.3",
59
60
  "esbuild": "^0.17.19",
60
61
  "istanbul-smart-text-reporter": "^1.1.2",
61
62
  "markdown-code-example-inserter": "^0.3.1",