@rvoh/dream 2.3.0-alpha.6 → 2.3.0-alpha.7
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
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { DateTime } from './DateTime.js';
|
|
2
|
+
export default class BaseClockTime {
|
|
3
|
+
dateTime;
|
|
4
|
+
_toSQL;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
constructor(source) {
|
|
9
|
+
if (source instanceof DateTime) {
|
|
10
|
+
this.dateTime = source;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.dateTime = DateTime.now();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a ClockTimeTz from a DateTime instance.
|
|
18
|
+
* @param dateTime - A DateTime instance
|
|
19
|
+
* @returns A ClockTimeTz for the time portion of the DateTime
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* ClockTime/ClockTimeTz.fromDateTime(DateTime.now())
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
static fromDateTime(dateTime) {
|
|
26
|
+
return new this(dateTime);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns true if this ClockTime equals another ClockTime.
|
|
30
|
+
* @param otherClockTime - ClockTime to compare
|
|
31
|
+
* @returns true if times are equal
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const t1 = ClockTime.fromObject({ hour: 14, minute: 30 })
|
|
35
|
+
* const t2 = ClockTime.fromObject({ hour: 14, minute: 30 })
|
|
36
|
+
* t1.equals(t2) // true
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
equals(otherClockTime) {
|
|
40
|
+
return this.valueOf() === otherClockTime.valueOf();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns a new ClockTime with the given time units set.
|
|
44
|
+
* @param values - Object with time units to set (hour, minute, second, millisecond, microsecond)
|
|
45
|
+
* @returns A new ClockTime
|
|
46
|
+
* @throws {InvalidClockTime} When the underlying DateTime operation fails
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* ClockTime.fromObject({ hour: 10, minute: 30 }).set({ hour: 14, microsecond: 500 })
|
|
50
|
+
* // hour: 14, minute: 30, microsecond: 500
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
set(values) {
|
|
54
|
+
return new this.constructor(this.wrapLuxonError(() => this.dateTime.set(values)));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns a new ClockTime at the start of the given period.
|
|
58
|
+
* @param period - Unit to truncate to ('hour', 'minute', or 'second')
|
|
59
|
+
* @returns A ClockTime at the start of the period
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* ClockTime.fromObject({ hour: 14, minute: 30, second: 45 }).startOf('hour')
|
|
63
|
+
* // hour: 14, minute: 0, second: 0
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
startOf(period) {
|
|
67
|
+
return new this.constructor(this.dateTime.startOf(period));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns a new ClockTime at the end of the given period.
|
|
71
|
+
* @param period - Unit to extend to end of ('hour', 'minute', or 'second')
|
|
72
|
+
* @returns A ClockTime at the end of the period
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* ClockTime.fromObject({ hour: 14, minute: 30 }).endOf('hour')
|
|
76
|
+
* // hour: 14, minute: 59, second: 59, millisecond: 999
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
endOf(period) {
|
|
80
|
+
return new this.constructor(this.dateTime.endOf(period));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the time as an ISO time string (for valueOf() operations).
|
|
84
|
+
* @returns ISO time string
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* ClockTime/ClockTimeTz.now().valueOf()
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
_valueOf;
|
|
91
|
+
valueOf() {
|
|
92
|
+
if (this._valueOf)
|
|
93
|
+
return this._valueOf;
|
|
94
|
+
this._valueOf = this.toISOTime();
|
|
95
|
+
return this._valueOf;
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
98
|
+
toISO(opts) {
|
|
99
|
+
throw new Error('override toISO in extending class');
|
|
100
|
+
}
|
|
101
|
+
toSQL() {
|
|
102
|
+
throw new Error('override toSQL in extending class');
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the time as an ISO 8601 time string with timezone offset.
|
|
106
|
+
* Alias for `toISO()`.
|
|
107
|
+
*
|
|
108
|
+
* @param opts - Optional format options
|
|
109
|
+
* @param opts.suppressMilliseconds - If true, omits milliseconds/microseconds when they are zero
|
|
110
|
+
* @param opts.suppressSeconds - If true, omits seconds when they are zero
|
|
111
|
+
* @param opts.format - Format variant: 'basic' (compact) or 'extended' (default, with colons)
|
|
112
|
+
* @returns ISO time string with timezone offset (e.g., '14:30:45.123456-05:00')
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).toISOTime() // '14:30:45.000000+00:00'
|
|
116
|
+
* ClockTime/ClockTimeTz.fromISO('14:30:45-05:00').toISOTime() // '14:30:45.000000-05:00'
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
toISOTime(opts) {
|
|
120
|
+
return this.toISO(opts);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the time as an ISO time string for JSON serialization.
|
|
124
|
+
* @returns ISO time string
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* JSON.stringify({ time: ClockTime.now() })
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
toJSON() {
|
|
131
|
+
return this.toISOTime();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Alias of `toSQL`.
|
|
135
|
+
* Returns the SQL time string without timezone offset.
|
|
136
|
+
* Result is memoized for performance.
|
|
137
|
+
*
|
|
138
|
+
* @returns SQL time string without timezone offset (e.g., '14:30:45.123456')
|
|
139
|
+
*/
|
|
140
|
+
toSQLTime() {
|
|
141
|
+
return this.toSQL();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns a localized string representation of the time.
|
|
145
|
+
* @param formatOpts - Intl.DateTimeFormat options for formatting
|
|
146
|
+
* @param opts - Optional locale configuration
|
|
147
|
+
* @param opts.locale - Locale string (e.g., 'en-US', 'fr-FR')
|
|
148
|
+
* @param opts.numberingSystem - Numbering system (e.g., 'arab', 'beng')
|
|
149
|
+
* @param opts.outputCalendar - Calendar system (e.g., 'islamic', 'hebrew')
|
|
150
|
+
* @returns Localized time string
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* ClockTime/ClockTimeTz.now().toLocaleString()
|
|
154
|
+
* ClockTime/ClockTimeTz.now().toLocaleString({ hour: 'numeric', minute: '2-digit' })
|
|
155
|
+
* ClockTime/ClockTimeTz.now().toLocaleString({ hour: '2-digit' }, { locale: 'fr-FR' })
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
toLocaleString(formatOpts, opts) {
|
|
159
|
+
return this.dateTime.toLocaleString(formatOpts, opts);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the time as an ISO string (same as toISO).
|
|
163
|
+
* @returns ISO datetime string
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* ClockTime.now().toString()
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
toString() {
|
|
170
|
+
return this.toISO();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns the underlying DateTime instance.
|
|
174
|
+
* @returns A DateTime representing this time with zone
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const dt = ClockTime/ClockTimeTz.now().toDateTime()
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
toDateTime() {
|
|
181
|
+
return this.dateTime;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the hour (0-23).
|
|
185
|
+
* @returns The hour number
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).hour // 14
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
get hour() {
|
|
192
|
+
return this.dateTime.hour;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Gets the minute (0-59).
|
|
196
|
+
* @returns The minute number
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).minute // 30
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
get minute() {
|
|
203
|
+
return this.dateTime.minute;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets the second (0-59).
|
|
207
|
+
* @returns The second number
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).second // 45
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
get second() {
|
|
214
|
+
return this.dateTime.second;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets the millisecond (0-999).
|
|
218
|
+
* @returns The millisecond number
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, millisecond: 123 }).millisecond // 123
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
get millisecond() {
|
|
225
|
+
return this.dateTime.millisecond;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets the microsecond (0-999).
|
|
229
|
+
* @returns The microsecond number
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* ClockTime/ClockTimeTz.fromISO('14:30:45.123456').microsecond // 456
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
get microsecond() {
|
|
236
|
+
return this.dateTime.microsecond;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns the earliest ClockTime/ClockTimeTz from the given arguments.
|
|
240
|
+
* @param clockTimes - ClockTime/ClockTimeTz instances to compare
|
|
241
|
+
* @returns The earliest ClockTime/ClockTimeTz
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* ClockTime/ClockTimeTz.min(time1, time2, time3)
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
static min(...clockTimes) {
|
|
248
|
+
if (clockTimes.length === 0)
|
|
249
|
+
return null;
|
|
250
|
+
return clockTimes.reduce((min, time) => (time.valueOf() < min.valueOf() ? time : min), clockTimes[0]);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Returns the latest ClockTime/ClockTimeTz from the given arguments.
|
|
254
|
+
* @param clockTimes - ClockTime/ClockTimeTz instances to compare
|
|
255
|
+
* @returns The latest ClockTime/ClockTimeTz
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* ClockTime/ClockTimeTz.max(time1, time2, time3)
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
static max(...clockTimes) {
|
|
262
|
+
if (clockTimes.length === 0)
|
|
263
|
+
return null;
|
|
264
|
+
return clockTimes.reduce((max, time) => (time.valueOf() > max.valueOf() ? time : max), clockTimes[0]);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Returns a new ClockTime/ClockTimeTz with the given duration added.
|
|
268
|
+
* @param duration - Duration to add (object with hours, minutes, seconds, etc.)
|
|
269
|
+
* @returns A new ClockTime/ClockTimeTz
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).plus({ hours: 2, minutes: 15 })
|
|
273
|
+
* // hour: 16, minute: 45
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
plus(duration) {
|
|
277
|
+
return new this.constructor(this.dateTime.plus(duration));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns a new ClockTime/ClockTimeTz with the given duration subtracted.
|
|
281
|
+
* @param duration - Duration to subtract (object with hours, minutes, seconds, etc.)
|
|
282
|
+
* @returns A new ClockTime/ClockTimeTz
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).minus({ hours: 2, minutes: 15 })
|
|
286
|
+
* // hour: 12, minute: 15
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
minus(duration) {
|
|
290
|
+
return new this.constructor(this.dateTime.minus(duration));
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns true if this and other are in the same unit of time.
|
|
294
|
+
* @param otherClockTime - ClockTime to compare against
|
|
295
|
+
* @param period - Unit to check ('hour', 'minute', or 'second')
|
|
296
|
+
* @returns true if same period
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* const t1 = ClockTime.fromObject({ hour: 14, minute: 30 })
|
|
300
|
+
* const t2 = ClockTime.fromObject({ hour: 14, minute: 45 })
|
|
301
|
+
* t1.hasSame(t2, 'hour') // true
|
|
302
|
+
* t1.hasSame(t2, 'minute') // false
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
hasSame(otherClockTime, period) {
|
|
306
|
+
const otherDateTime = otherClockTime.toDateTime();
|
|
307
|
+
if (otherDateTime === null)
|
|
308
|
+
return false;
|
|
309
|
+
return this.dateTime.hasSame(otherDateTime, period);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Returns the difference between this ClockTime and another in the specified unit.
|
|
313
|
+
* @param otherClockTime - ClockTime to compare against
|
|
314
|
+
* @param duration - Unit for the difference ('hours', 'minutes', 'seconds', etc.)
|
|
315
|
+
* @returns Numeric difference in the specified unit
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* const t1 = ClockTime.fromObject({ hour: 14, minute: 30 })
|
|
319
|
+
* const t2 = ClockTime.fromObject({ hour: 10, minute: 15 })
|
|
320
|
+
* t1.diff(t2, 'hours') // 4.25
|
|
321
|
+
* t1.diff(t2, 'minutes') // 255
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
/**
|
|
325
|
+
* Returns the difference between this ClockTime and another in the specified unit(s).
|
|
326
|
+
* Supports microsecond precision when 'microseconds' is included in the unit parameter.
|
|
327
|
+
*
|
|
328
|
+
* @param other - ClockTime to compare against
|
|
329
|
+
* @param unit - Unit or units to return (hours, minutes, seconds, milliseconds, microseconds)
|
|
330
|
+
* @returns Object with only the specified units (or all units if not specified)
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* const t1 = ClockTime.fromObject({ hour: 15, minute: 30 })
|
|
334
|
+
* const t2 = ClockTime.fromObject({ hour: 14, minute: 0 })
|
|
335
|
+
* t1.diff(t2, 'hours') // { hours: 1 }
|
|
336
|
+
* t1.diff(t2, ['hours', 'minutes']) // { hours: 1, minutes: 30 }
|
|
337
|
+
* t1.diff(t2) // { hours: 1, minutes: 30, seconds: 0, milliseconds: 0, microseconds: 0 }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
diff(other, unit) {
|
|
341
|
+
const otherDateTime = other.toDateTime();
|
|
342
|
+
const unitArray = unit === undefined ? undefined : Array.isArray(unit) ? unit : [unit];
|
|
343
|
+
const result = this.dateTime.diff(otherDateTime, unitArray);
|
|
344
|
+
const filtered = {};
|
|
345
|
+
const requestedUnits = unit === undefined
|
|
346
|
+
? ['hours', 'minutes', 'seconds', 'milliseconds', 'microseconds']
|
|
347
|
+
: Array.isArray(unit)
|
|
348
|
+
? unit
|
|
349
|
+
: [unit];
|
|
350
|
+
for (const requestedUnit of requestedUnits) {
|
|
351
|
+
filtered[requestedUnit] = result[requestedUnit] ?? 0;
|
|
352
|
+
}
|
|
353
|
+
return filtered;
|
|
354
|
+
}
|
|
355
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
356
|
+
static wrapLuxonError(fn) {
|
|
357
|
+
throw new Error('override wrapLuxonError static method in extending class');
|
|
358
|
+
}
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
360
|
+
wrapLuxonError(fn) {
|
|
361
|
+
throw new Error('override wrapLuxonError instance method in extending class');
|
|
362
|
+
}
|
|
363
|
+
}
|