@rvoh/dream 2.3.0-alpha.6 → 2.3.0-alpha.8
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/dist/cjs/src/Dream.js +2 -40
- package/dist/cjs/src/cli/index.js +4 -0
- package/dist/cjs/src/dream/Query.js +14 -11
- package/dist/cjs/src/dream/QueryDriver/Base.js +0 -14
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +86 -74
- package/dist/cjs/src/dream/QueryDriver/Postgres.js +10 -2
- package/dist/cjs/src/dream/internal/extractAssignableAssociationAttributes.js +9 -0
- package/dist/cjs/src/errors/db/DataIncompatibleWithDatabaseField.js +1 -3
- package/dist/cjs/src/helpers/areEqual.js +5 -0
- package/dist/cjs/src/helpers/cli/ASTBuilder.js +54 -2
- package/dist/cjs/src/helpers/cli/ASTKyselyCodegenEnhancer.js +84 -0
- package/dist/cjs/src/helpers/cli/ASTSchemaBuilder.js +17 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +16 -0
- package/dist/cjs/src/helpers/cloneDeepSafe.js +21 -10
- package/dist/cjs/src/helpers/customPgParsers.js +18 -1
- package/dist/cjs/src/helpers/db/normalizeDataForDb.js +81 -0
- package/dist/cjs/src/helpers/db/types/helpers.js +5 -0
- package/dist/cjs/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
- package/dist/cjs/src/helpers/sortBy.js +7 -5
- package/dist/cjs/src/helpers/sqlAttributes.js +4 -53
- package/dist/cjs/src/helpers/stringCasing.js +6 -5
- package/dist/cjs/src/helpers/toSafeObject.js +17 -0
- package/dist/cjs/src/package-exports/errors.js +2 -0
- package/dist/cjs/src/package-exports/index.js +2 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +11 -11
- package/dist/cjs/src/types/clocktime.js +1 -0
- package/dist/cjs/src/utils/datetime/BaseClockTime.js +363 -0
- package/dist/cjs/src/utils/datetime/CalendarDate.js +110 -119
- package/dist/cjs/src/utils/datetime/ClockTime.js +173 -0
- package/dist/cjs/src/utils/datetime/ClockTimeTz.js +232 -0
- package/dist/cjs/src/utils/datetime/DateTime.js +288 -193
- package/dist/cjs/src/utils/datetime/helpers/isoTimeDecimalString.js +1 -1
- package/dist/esm/src/Dream.js +2 -40
- package/dist/esm/src/cli/index.js +4 -0
- package/dist/esm/src/dream/Query.js +14 -11
- package/dist/esm/src/dream/QueryDriver/Base.js +0 -14
- package/dist/esm/src/dream/QueryDriver/Kysely.js +86 -74
- package/dist/esm/src/dream/QueryDriver/Postgres.js +10 -2
- package/dist/esm/src/dream/internal/extractAssignableAssociationAttributes.js +9 -0
- package/dist/esm/src/errors/db/DataIncompatibleWithDatabaseField.js +1 -3
- package/dist/esm/src/helpers/areEqual.js +5 -0
- package/dist/esm/src/helpers/cli/ASTBuilder.js +54 -2
- package/dist/esm/src/helpers/cli/ASTKyselyCodegenEnhancer.js +84 -0
- package/dist/esm/src/helpers/cli/ASTSchemaBuilder.js +17 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +16 -0
- package/dist/esm/src/helpers/cloneDeepSafe.js +21 -10
- package/dist/esm/src/helpers/customPgParsers.js +18 -1
- package/dist/esm/src/helpers/db/normalizeDataForDb.js +81 -0
- package/dist/esm/src/helpers/db/types/helpers.js +5 -0
- package/dist/esm/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
- package/dist/esm/src/helpers/sortBy.js +7 -5
- package/dist/esm/src/helpers/sqlAttributes.js +4 -53
- package/dist/esm/src/helpers/stringCasing.js +6 -5
- package/dist/esm/src/helpers/toSafeObject.js +17 -0
- package/dist/esm/src/package-exports/errors.js +2 -0
- package/dist/esm/src/package-exports/index.js +2 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +11 -11
- package/dist/esm/src/types/clocktime.js +1 -0
- package/dist/esm/src/utils/datetime/BaseClockTime.js +363 -0
- package/dist/esm/src/utils/datetime/CalendarDate.js +110 -119
- package/dist/esm/src/utils/datetime/ClockTime.js +173 -0
- package/dist/esm/src/utils/datetime/ClockTimeTz.js +232 -0
- package/dist/esm/src/utils/datetime/DateTime.js +288 -193
- package/dist/esm/src/utils/datetime/helpers/isoTimeDecimalString.js +1 -1
- package/dist/types/src/Dream.d.ts +29 -33
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +9 -10
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +16 -16
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +1 -1
- package/dist/types/src/dream/LoadBuilder.d.ts +1 -1
- package/dist/types/src/dream/Query.d.ts +16 -16
- package/dist/types/src/dream/QueryDriver/Base.d.ts +0 -1
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -0
- package/dist/types/src/dream/internal/associations/associationQuery.d.ts +1 -1
- package/dist/types/src/dream/internal/associations/associationUpdateQuery.d.ts +1 -1
- package/dist/types/src/dream/internal/associations/destroyAssociation.d.ts +1 -1
- package/dist/types/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.d.ts +4 -2
- package/dist/types/src/dream/internal/associations/undestroyAssociation.d.ts +1 -1
- package/dist/types/src/dream/internal/extractAssignableAssociationAttributes.d.ts +3 -0
- package/dist/types/src/dream/internal/similarity/SimilarityBuilder.d.ts +7 -7
- package/dist/types/src/errors/db/DataIncompatibleWithDatabaseField.d.ts +2 -7
- package/dist/types/src/helpers/cli/ASTBuilder.d.ts +31 -0
- package/dist/types/src/helpers/cli/ASTKyselyCodegenEnhancer.d.ts +13 -0
- package/dist/types/src/helpers/customPgParsers.d.ts +5 -0
- package/dist/types/src/helpers/db/normalizeDataForDb.d.ts +6 -0
- package/dist/types/src/helpers/db/types/helpers.d.ts +5 -0
- package/dist/types/src/helpers/sort.d.ts +2 -1
- package/dist/types/src/helpers/sortBy.d.ts +3 -0
- package/dist/types/src/helpers/toSafeObject.d.ts +8 -0
- package/dist/types/src/package-exports/errors.d.ts +2 -0
- package/dist/types/src/package-exports/index.d.ts +2 -0
- package/dist/types/src/package-exports/types.d.ts +2 -1
- package/dist/types/src/types/associations/shared.d.ts +15 -13
- package/dist/types/src/types/associations/shared.ts +81 -41
- package/dist/types/src/types/calendardate.d.ts +22 -1
- package/dist/types/src/types/calendardate.ts +33 -1
- package/dist/types/src/types/clocktime.d.ts +22 -0
- package/dist/types/src/types/clocktime.ts +59 -0
- package/dist/types/src/types/datetime.d.ts +11 -18
- package/dist/types/src/types/datetime.ts +16 -21
- package/dist/types/src/types/dream.d.ts +27 -13
- package/dist/types/src/types/dream.ts +40 -14
- package/dist/types/src/types/variadic.d.ts +10 -9
- package/dist/types/src/types/variadic.ts +30 -5
- package/dist/types/src/utils/datetime/BaseClockTime.d.ts +287 -0
- package/dist/types/src/utils/datetime/CalendarDate.d.ts +65 -47
- package/dist/types/src/utils/datetime/ClockTime.d.ts +138 -0
- package/dist/types/src/utils/datetime/ClockTimeTz.d.ts +194 -0
- package/dist/types/src/utils/datetime/DateTime.d.ts +142 -56
- package/dist/types/src/utils/datetime/helpers/isoTimeDecimalString.d.ts +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +9 -9
- package/docs/classes/db.KyselyQueryDriver.html +33 -34
- package/docs/classes/db.PostgresQueryDriver.html +34 -35
- package/docs/classes/db.QueryDriverBase.html +32 -33
- package/docs/classes/errors.CheckConstraintViolation.html +4 -6
- package/docs/classes/errors.ColumnOverflow.html +4 -6
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +4 -6
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +4 -6
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +17 -0
- package/docs/classes/errors.InvalidClockTimeTz.html +17 -0
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +4 -6
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +80 -92
- package/docs/classes/index.ClockTime.html +232 -0
- package/docs/classes/index.ClockTimeTz.html +253 -0
- package/docs/classes/index.DateTime.html +123 -129
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +127 -127
- package/docs/classes/index.DreamApp.html +5 -5
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +71 -71
- package/docs/classes/system.CliFileWriter.html +2 -2
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +5 -5
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +8 -8
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +2 -2
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range-1.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DurationObject.html +5 -5
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/modules/db.html +1 -1
- package/docs/modules/errors.html +3 -1
- package/docs/modules/index.html +3 -1
- package/docs/modules/openapi.html +1 -1
- package/docs/modules/system.html +1 -1
- package/docs/modules/types.html +3 -1
- package/docs/modules/utils.html +1 -1
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +2 -0
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +2 -0
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +1 -1
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +2 -4
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +1 -1
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +2 -2
- package/dist/cjs/src/helpers/db/types/isDateOrDateArrayColumn.js +0 -3
- package/dist/cjs/src/helpers/db/types/isTextOrTextArrayColumn.js +0 -3
- package/dist/esm/src/helpers/db/types/isDateOrDateArrayColumn.js +0 -3
- package/dist/esm/src/helpers/db/types/isTextOrTextArrayColumn.js +0 -3
- package/dist/types/src/helpers/db/types/isDateOrDateArrayColumn.d.ts +0 -2
- package/dist/types/src/helpers/db/types/isTextOrTextArrayColumn.d.ts +0 -2
|
@@ -1,38 +1,21 @@
|
|
|
1
|
-
import { DateTime } from './DateTime.js';
|
|
1
|
+
import { BASE_DATE_OBJECT, DateTime } from './DateTime.js';
|
|
2
2
|
/**
|
|
3
3
|
* CalendarDate represents a date without time or timezone information.
|
|
4
4
|
*/
|
|
5
5
|
export default class CalendarDate {
|
|
6
6
|
dateTime;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param source - DateTime instance, year number, or null/undefined for today
|
|
10
|
-
* @param month - Month (1-12) when source is a year number
|
|
11
|
-
* @param day - Day of month when source is a year number
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* new CalendarDate() // today
|
|
15
|
-
* new CalendarDate(DateTime.now()) // from DateTime
|
|
16
|
-
* new CalendarDate(2026, 2, 7) // February 7, 2026
|
|
17
|
-
* ```
|
|
8
|
+
* @internal
|
|
18
9
|
*/
|
|
19
|
-
constructor(source
|
|
20
|
-
if (source instanceof DateTime
|
|
21
|
-
|
|
22
|
-
this.dateTime = DateTime.fromISO(isoDate, { zone: 'UTC' });
|
|
10
|
+
constructor(source) {
|
|
11
|
+
if (source instanceof DateTime) {
|
|
12
|
+
this.dateTime = DateTime.fromISO(source.toISODate(), { zone: 'UTC' });
|
|
23
13
|
}
|
|
24
|
-
else if (typeof source === '
|
|
25
|
-
|
|
26
|
-
this.dateTime = DateTime.utc(source, month, day);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
if (error instanceof Error)
|
|
30
|
-
throw new InvalidCalendarDate(error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
14
|
+
else if (source && typeof source === 'object') {
|
|
15
|
+
this.dateTime = wrapLuxonError(() => DateTime.utc(source.year ?? BASE_DATE_OBJECT.year, source.month ?? BASE_DATE_OBJECT.month, source.day ?? BASE_DATE_OBJECT.day));
|
|
33
16
|
}
|
|
34
17
|
else {
|
|
35
|
-
this.dateTime =
|
|
18
|
+
this.dateTime = DateTime.now();
|
|
36
19
|
}
|
|
37
20
|
}
|
|
38
21
|
/**
|
|
@@ -58,8 +41,8 @@ export default class CalendarDate {
|
|
|
58
41
|
* CalendarDate.fromJSDate(new Date(), { zone: 'America/New_York' })
|
|
59
42
|
* ```
|
|
60
43
|
*/
|
|
61
|
-
static fromJSDate(javascriptDate,
|
|
62
|
-
return new CalendarDate(DateTime.fromJSDate(javascriptDate,
|
|
44
|
+
static fromJSDate(javascriptDate, opts = {}) {
|
|
45
|
+
return new CalendarDate(DateTime.fromJSDate(javascriptDate, opts));
|
|
63
46
|
}
|
|
64
47
|
/**
|
|
65
48
|
* Create a CalendarDate from an ISO 8601 date string.
|
|
@@ -70,19 +53,10 @@ export default class CalendarDate {
|
|
|
70
53
|
* @example
|
|
71
54
|
* ```ts
|
|
72
55
|
* CalendarDate.fromISO('2026-02-07')
|
|
73
|
-
* CalendarDate.fromISO('2026-02-07T09:00:00Z') // time portion ignored
|
|
74
56
|
* ```
|
|
75
57
|
*/
|
|
76
|
-
static fromISO(str,
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
dateTime = DateTime.fromISO(str, zone ? { zone } : { setZone: true });
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (error instanceof Error)
|
|
83
|
-
throw new InvalidCalendarDate(error);
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
58
|
+
static fromISO(str, opts = {}) {
|
|
59
|
+
const dateTime = wrapLuxonError(() => DateTime.fromISO(str, opts));
|
|
86
60
|
return new CalendarDate(dateTime);
|
|
87
61
|
}
|
|
88
62
|
/**
|
|
@@ -96,15 +70,7 @@ export default class CalendarDate {
|
|
|
96
70
|
* ```
|
|
97
71
|
*/
|
|
98
72
|
static fromSQL(str) {
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
dateTime = DateTime.fromSQL(str, { zone: 'UTC' });
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (error instanceof Error)
|
|
105
|
-
throw new InvalidCalendarDate(error);
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
73
|
+
const dateTime = wrapLuxonError(() => DateTime.fromSQL(str, { zone: 'UTC' }));
|
|
108
74
|
return new CalendarDate(dateTime);
|
|
109
75
|
}
|
|
110
76
|
/**
|
|
@@ -122,21 +88,8 @@ export default class CalendarDate {
|
|
|
122
88
|
* CalendarDate.fromFormat('mai 25, 1982', 'MMMM dd, yyyy', { locale: 'fr' })
|
|
123
89
|
* ```
|
|
124
90
|
*/
|
|
125
|
-
static fromFormat(text, format,
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
const opts = {};
|
|
129
|
-
if (zone)
|
|
130
|
-
opts.zone = zone;
|
|
131
|
-
if (locale)
|
|
132
|
-
opts.locale = locale;
|
|
133
|
-
dateTime = DateTime.fromFormat(text, format, opts);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
if (error instanceof Error)
|
|
137
|
-
throw new InvalidCalendarDate(error);
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
91
|
+
static fromFormat(text, format, opts) {
|
|
92
|
+
const dateTime = wrapLuxonError(() => DateTime.fromFormat(text, format, opts));
|
|
140
93
|
return new CalendarDate(dateTime);
|
|
141
94
|
}
|
|
142
95
|
/**
|
|
@@ -151,15 +104,7 @@ export default class CalendarDate {
|
|
|
151
104
|
* ```
|
|
152
105
|
*/
|
|
153
106
|
static fromObject(obj, opts) {
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
dateTime = DateTime.fromObject(obj, opts);
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
if (error instanceof Error)
|
|
160
|
-
throw new InvalidCalendarDate(error);
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
107
|
+
const dateTime = wrapLuxonError(() => DateTime.fromObject(obj, opts));
|
|
163
108
|
return new CalendarDate(dateTime);
|
|
164
109
|
}
|
|
165
110
|
/**
|
|
@@ -172,8 +117,8 @@ export default class CalendarDate {
|
|
|
172
117
|
* CalendarDate.today({ zone: 'America/New_York' })
|
|
173
118
|
* ```
|
|
174
119
|
*/
|
|
175
|
-
static today(
|
|
176
|
-
return new CalendarDate(DateTime.now()
|
|
120
|
+
static today(opts) {
|
|
121
|
+
return new CalendarDate(DateTime.now(opts));
|
|
177
122
|
}
|
|
178
123
|
/**
|
|
179
124
|
* Returns a CalendarDate for tomorrow's date.
|
|
@@ -212,6 +157,19 @@ export default class CalendarDate {
|
|
|
212
157
|
toISO() {
|
|
213
158
|
return this.dateTime.toISODate();
|
|
214
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the date as an ISO date string.
|
|
162
|
+
* Alias for `toISO()`.
|
|
163
|
+
*
|
|
164
|
+
* @returns ISO date string (e.g., '2026-02-07')
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* CalendarDate.fromObject({ year: 2026, month: 2, day: 7 }).toISODate() // '2026-02-07'
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
toISODate() {
|
|
171
|
+
return this.toISO();
|
|
172
|
+
}
|
|
215
173
|
/**
|
|
216
174
|
* Returns the date as an SQL date string.
|
|
217
175
|
* @returns SQL date string (e.g., '2026-02-07')
|
|
@@ -220,8 +178,12 @@ export default class CalendarDate {
|
|
|
220
178
|
* CalendarDate.fromObject({ year: 2026, month: 2, day: 7 }).toSQL() // '2026-02-07'
|
|
221
179
|
* ```
|
|
222
180
|
*/
|
|
181
|
+
_toSQL;
|
|
223
182
|
toSQL() {
|
|
224
|
-
|
|
183
|
+
if (this._toSQL)
|
|
184
|
+
return this._toSQL;
|
|
185
|
+
this._toSQL = this.dateTime.toSQLDate();
|
|
186
|
+
return this._toSQL;
|
|
225
187
|
}
|
|
226
188
|
/**
|
|
227
189
|
* Returns the date as an ISO string for JSON serialization.
|
|
@@ -235,26 +197,19 @@ export default class CalendarDate {
|
|
|
235
197
|
return this.toISO();
|
|
236
198
|
}
|
|
237
199
|
/**
|
|
238
|
-
* Returns the
|
|
239
|
-
* @returns
|
|
200
|
+
* Returns the date as an ISO date string (for valueOf() operations).
|
|
201
|
+
* @returns ISO date string (e.g., '2026-02-07')
|
|
240
202
|
* @example
|
|
241
203
|
* ```ts
|
|
242
204
|
* CalendarDate.fromISO('2026-02-07').valueOf()
|
|
243
205
|
* ```
|
|
244
206
|
*/
|
|
207
|
+
_valueOf;
|
|
245
208
|
valueOf() {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
* @returns ISO date string (e.g., '2026-02-07')
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* CalendarDate.fromObject({ year: 2026, month: 2, day: 7 }).toISODate() // '2026-02-07'
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
toISODate() {
|
|
257
|
-
return this.toISO();
|
|
209
|
+
if (this._valueOf)
|
|
210
|
+
return this._valueOf;
|
|
211
|
+
this._valueOf = this.toISO();
|
|
212
|
+
return this._valueOf;
|
|
258
213
|
}
|
|
259
214
|
/**
|
|
260
215
|
* Returns a localized string representation of the date.
|
|
@@ -401,17 +356,17 @@ export default class CalendarDate {
|
|
|
401
356
|
return new CalendarDate(this.dateTime.minus(duration));
|
|
402
357
|
}
|
|
403
358
|
/**
|
|
404
|
-
* Returns
|
|
405
|
-
* @param
|
|
406
|
-
* @returns
|
|
359
|
+
* Returns a new CalendarDate with the given date units set.
|
|
360
|
+
* @param values - Object with date units to set (year, month, day)
|
|
361
|
+
* @returns A new CalendarDate
|
|
362
|
+
* @throws {InvalidCalendarDate} When the underlying DateTime operation fails
|
|
407
363
|
* @example
|
|
408
364
|
* ```ts
|
|
409
|
-
* CalendarDate.
|
|
365
|
+
* CalendarDate.fromISO('2026-02-07').set({ year: 2025, day: 15 }) // 2025-02-15
|
|
410
366
|
* ```
|
|
411
367
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return new CalendarDate(DateTime.max(...dateTimes));
|
|
368
|
+
set(values) {
|
|
369
|
+
return new CalendarDate(wrapLuxonError(() => this.dateTime.set(values)));
|
|
415
370
|
}
|
|
416
371
|
/**
|
|
417
372
|
* Returns the earliest CalendarDate from the given arguments.
|
|
@@ -423,8 +378,23 @@ export default class CalendarDate {
|
|
|
423
378
|
* ```
|
|
424
379
|
*/
|
|
425
380
|
static min(...calendarDates) {
|
|
426
|
-
|
|
427
|
-
|
|
381
|
+
if (calendarDates.length === 0)
|
|
382
|
+
return null;
|
|
383
|
+
return calendarDates.reduce((min, calendarDate) => (calendarDate.valueOf() < min.valueOf() ? calendarDate : min), calendarDates[0]);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Returns the latest CalendarDate from the given arguments.
|
|
387
|
+
* @param calendarDates - CalendarDates to compare
|
|
388
|
+
* @returns The latest CalendarDate
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* CalendarDate.max(date1, date2, date3)
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
static max(...calendarDates) {
|
|
395
|
+
if (calendarDates.length === 0)
|
|
396
|
+
return null;
|
|
397
|
+
return calendarDates.reduce((max, calendarDate) => (calendarDate.valueOf() > max.valueOf() ? calendarDate : max), calendarDates[0]);
|
|
428
398
|
}
|
|
429
399
|
/**
|
|
430
400
|
* Returns true if this and other are in the same unit of time.
|
|
@@ -455,37 +425,48 @@ export default class CalendarDate {
|
|
|
455
425
|
* const d1 = CalendarDate.fromISO('2026-02-07')
|
|
456
426
|
* const d2 = CalendarDate.fromISO('2026-02-15')
|
|
457
427
|
* d2.diff(d1, 'days') // 8
|
|
458
|
-
* d2.diff(d1, 'months') // 0
|
|
459
428
|
* ```
|
|
460
429
|
*/
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
430
|
+
/**
|
|
431
|
+
* Returns the difference between this CalendarDate and another in the specified unit(s).
|
|
432
|
+
*
|
|
433
|
+
* @param other - CalendarDate to compare against
|
|
434
|
+
* @param unit - Unit or units to return (years, quarters, months, weeks, days)
|
|
435
|
+
* @returns Object with only the specified units (or all units if not specified)
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* const d1 = CalendarDate.fromISO('2026-02-15')
|
|
439
|
+
* const d2 = CalendarDate.fromISO('2026-02-07')
|
|
440
|
+
* d1.diff(d2, 'days') // { days: 8 }
|
|
441
|
+
* d1.diff(d2, ['months', 'days']) // { months: 0, days: 8 }
|
|
442
|
+
* d1.diff(d2) // { years: 0, months: 0, days: 8 }
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
diff(other, unit) {
|
|
446
|
+
const otherDateTime = other.toDateTime();
|
|
447
|
+
const unitArray = unit === undefined ? undefined : Array.isArray(unit) ? unit : [unit];
|
|
448
|
+
const result = this.dateTime.diff(otherDateTime, unitArray);
|
|
449
|
+
const filtered = {};
|
|
450
|
+
const requestedUnits = unit === undefined ? ['years', 'months', 'days'] : Array.isArray(unit) ? unit : [unit];
|
|
451
|
+
for (const requestedUnit of requestedUnits) {
|
|
452
|
+
filtered[requestedUnit] = result[requestedUnit] ?? 0;
|
|
467
453
|
}
|
|
468
|
-
|
|
469
|
-
return result[duration] ?? 0;
|
|
454
|
+
return filtered;
|
|
470
455
|
}
|
|
471
456
|
/**
|
|
472
|
-
* Returns the difference between this CalendarDate and today in the specified unit.
|
|
473
|
-
*
|
|
474
|
-
* @
|
|
457
|
+
* Returns the difference between this CalendarDate and today in the specified unit(s).
|
|
458
|
+
*
|
|
459
|
+
* @param unit - Unit or units to return (years, quarters, months, weeks, days)
|
|
460
|
+
* @returns Object with only the specified units (or all units if not specified)
|
|
475
461
|
* @example
|
|
476
462
|
* ```ts
|
|
477
463
|
* const future = CalendarDate.today().plus({ days: 5 })
|
|
478
|
-
* future.diffNow('days') //
|
|
464
|
+
* future.diffNow('days') // { days: 5 }
|
|
465
|
+
* future.diffNow(['months', 'days']) // { months: 0, days: 5 }
|
|
479
466
|
* ```
|
|
480
467
|
*/
|
|
481
|
-
diffNow(
|
|
482
|
-
|
|
483
|
-
if (duration === 'quarters' || duration === 'months') {
|
|
484
|
-
const luxonDiff = this.dateTime.toLuxon().diffNow(duration);
|
|
485
|
-
return Math.ceil(luxonDiff[duration] ?? 0);
|
|
486
|
-
}
|
|
487
|
-
const result = this.dateTime.diffNow(duration);
|
|
488
|
-
return Math.ceil(result[duration] ?? 0);
|
|
468
|
+
diffNow(unit) {
|
|
469
|
+
return this.diff(CalendarDate.today(), unit);
|
|
489
470
|
}
|
|
490
471
|
/**
|
|
491
472
|
* Returns true if this CalendarDate equals another CalendarDate.
|
|
@@ -499,7 +480,7 @@ export default class CalendarDate {
|
|
|
499
480
|
* ```
|
|
500
481
|
*/
|
|
501
482
|
equals(otherCalendarDate) {
|
|
502
|
-
return this.
|
|
483
|
+
return this.valueOf() === otherCalendarDate.valueOf();
|
|
503
484
|
}
|
|
504
485
|
}
|
|
505
486
|
/**
|
|
@@ -519,3 +500,13 @@ export class InvalidCalendarDate extends Error {
|
|
|
519
500
|
super((error.message ?? '').replace('DateTime', 'CalendarDate'));
|
|
520
501
|
}
|
|
521
502
|
}
|
|
503
|
+
function wrapLuxonError(fn) {
|
|
504
|
+
try {
|
|
505
|
+
return fn();
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
if (error instanceof Error)
|
|
509
|
+
throw new InvalidCalendarDate(error);
|
|
510
|
+
throw error;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import BaseClockTime from './BaseClockTime.js';
|
|
2
|
+
import { BASE_DATE_OBJECT, DateTime } from './DateTime.js';
|
|
3
|
+
/**
|
|
4
|
+
* ClockTime represents a time of day without timezone information.
|
|
5
|
+
*
|
|
6
|
+
* Useful for representing TIME WITHOUT TIME ZONE fields from a Postgres database.
|
|
7
|
+
* All output methods strip timezone offset information.
|
|
8
|
+
*/
|
|
9
|
+
export default class ClockTime extends BaseClockTime {
|
|
10
|
+
/**
|
|
11
|
+
* Create a ClockTime from a JavaScript Date.
|
|
12
|
+
* @param javascriptDate - A JavaScript Date instance
|
|
13
|
+
* @returns A ClockTime for the time portion
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* ClockTime.fromJSDate(new Date())
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
static fromJSDate(javascriptDate) {
|
|
20
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromJSDate(javascriptDate));
|
|
21
|
+
return new ClockTime(dateTime);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a ClockTime from an ISO 8601 time string.
|
|
25
|
+
* Preserves the time values as-is, regardless of any timezone info in the string.
|
|
26
|
+
* @param str - ISO time string (e.g., '14:30:45.123456')
|
|
27
|
+
* @returns A ClockTime for the given time
|
|
28
|
+
* @throws {InvalidClockTime} When the ISO string is invalid
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* ClockTime.fromISO('14:30:45.123456') // stores 14:30:45.123456
|
|
32
|
+
* ClockTime.fromISO('14:30:45.123456-05:00') // stores 14:30:45.123456 (timezone ignored)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
static fromISO(str) {
|
|
36
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromISO(str));
|
|
37
|
+
return new ClockTime(dateTime);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a ClockTime from an SQL time string.
|
|
41
|
+
* Preserves the time values as-is, regardless of any timezone info in the string.
|
|
42
|
+
* @param str - SQL time string (e.g., '14:30:45.123456')
|
|
43
|
+
* @returns A ClockTime for the given time
|
|
44
|
+
* @throws {InvalidClockTime} When the SQL string is invalid
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* ClockTime.fromSQL('14:30:45.123456') // stores 14:30:45.123456
|
|
48
|
+
* ClockTime.fromSQL('14:30:45.123456+05:30') // stores 14:30:45.123456 (timezone ignored)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
static fromSQL(str) {
|
|
52
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromSQL(str));
|
|
53
|
+
return new ClockTime(dateTime);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a ClockTime from a custom format string.
|
|
57
|
+
* Uses Luxon format tokens (e.g., 'HH:mm:ss', 'hh:mm a').
|
|
58
|
+
* @param text - The string to parse
|
|
59
|
+
* @param format - Format string using Luxon tokens
|
|
60
|
+
* @param opts - Optional configuration
|
|
61
|
+
* @param opts.locale - Locale for parsing (e.g., 'en-US', 'fr-FR')
|
|
62
|
+
* @param opts.numberingSystem - Numbering system (e.g., 'arab', 'beng')
|
|
63
|
+
* @param opts.outputCalendar - Output calendar system (e.g., 'islamic', 'hebrew')
|
|
64
|
+
* @returns A ClockTime for the parsed time
|
|
65
|
+
* @throws {InvalidClockTime} When the string doesn't match the format or is invalid
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* ClockTime.fromFormat('14:30:45', 'HH:mm:ss')
|
|
69
|
+
* ClockTime.fromFormat('2:30 PM', 'h:mm a')
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
static fromFormat(text, format, opts) {
|
|
73
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromFormat(text, format, opts));
|
|
74
|
+
return new ClockTime(dateTime);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a ClockTime from an object with time units.
|
|
78
|
+
* @param obj - Object with hour, minute, second, millisecond, microsecond properties
|
|
79
|
+
* @param opts - Optional configuration
|
|
80
|
+
* @param opts.locale - Locale (e.g., 'en-US', 'fr-FR')
|
|
81
|
+
* @param opts.numberingSystem - Numbering system (e.g., 'arab', 'beng')
|
|
82
|
+
* @param opts.outputCalendar - Output calendar system (e.g., 'islamic', 'hebrew')
|
|
83
|
+
* @returns A ClockTime for the given components
|
|
84
|
+
* @throws {InvalidClockTime} When time values are invalid
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* ClockTime.fromObject({ hour: 14, minute: 30, second: 45 })
|
|
88
|
+
* ClockTime.fromObject({ hour: 14, minute: 30 })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
static fromObject(obj, opts) {
|
|
92
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromObject({
|
|
93
|
+
...BASE_DATE_OBJECT,
|
|
94
|
+
...obj,
|
|
95
|
+
}, opts));
|
|
96
|
+
return new ClockTime(dateTime);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns a ClockTime for the current time.
|
|
100
|
+
* @returns A ClockTime for now
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* ClockTime.now()
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
static now() {
|
|
107
|
+
return new ClockTime(DateTime.now());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the time as an ISO 8601 time string without timezone offset.
|
|
111
|
+
* Alias for `toISOTime()`.
|
|
112
|
+
*
|
|
113
|
+
* @param opts - Optional format options
|
|
114
|
+
* @param opts.suppressMilliseconds - If true, omits milliseconds/microseconds when they are zero
|
|
115
|
+
* @param opts.suppressSeconds - If true, omits seconds when they are zero
|
|
116
|
+
* @param opts.format - Format variant: 'basic' (compact) or 'extended' (default, with colons)
|
|
117
|
+
* @returns ISO time string without timezone offset (e.g., '14:30:45.123456')
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* ClockTime.fromObject({ hour: 14, minute: 30, second: 45 }).toISO() // '14:30:45.000000'
|
|
121
|
+
* ClockTime.fromISO('14:30:45-05:00').toISO() // '14:30:45.000000' (timezone stripped)
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
toISO(opts) {
|
|
125
|
+
return this.dateTime.toISOTime({ ...opts, includeOffset: false });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the SQL time string without timezone offset.
|
|
129
|
+
* Result is memoized for performance.
|
|
130
|
+
*
|
|
131
|
+
* @returns SQL time string without timezone offset (e.g., '14:30:45.123456')
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* ClockTime.fromISO('14:30:45').toSQL() // '14:30:45.000000'
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
toSQL() {
|
|
138
|
+
if (this._toSQL)
|
|
139
|
+
return this._toSQL;
|
|
140
|
+
this._toSQL = this.dateTime.toSQLTime({ includeOffset: false });
|
|
141
|
+
return this._toSQL;
|
|
142
|
+
}
|
|
143
|
+
static wrapLuxonError(fn) {
|
|
144
|
+
try {
|
|
145
|
+
return fn();
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error instanceof Error)
|
|
149
|
+
throw new InvalidClockTime(error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
wrapLuxonError(fn) {
|
|
154
|
+
return this.constructor.wrapLuxonError(fn);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Thrown when a ClockTime is invalid (e.g., invalid input or time values).
|
|
159
|
+
* @param error - The original error (available as cause)
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* try {
|
|
163
|
+
* ClockTime.fromISO('25:00:00')
|
|
164
|
+
* } catch (e) {
|
|
165
|
+
* if (e instanceof InvalidClockTime) console.error(e.message)
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export class InvalidClockTime extends Error {
|
|
170
|
+
constructor(error) {
|
|
171
|
+
super((error.message ?? '').replace('DateTime', 'ClockTime'));
|
|
172
|
+
}
|
|
173
|
+
}
|