@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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import BaseClockTime from './BaseClockTime.js';
|
|
2
|
+
import { DateTime } from './DateTime.js';
|
|
3
|
+
/**
|
|
4
|
+
* ClockTimeTz represents a time of day with timezone information.
|
|
5
|
+
*
|
|
6
|
+
* Useful for representing TIME WITH TIME ZONE fields from a Postgres database.
|
|
7
|
+
* All output methods include timezone offset information.
|
|
8
|
+
*/
|
|
9
|
+
export default class ClockTimeTz extends BaseClockTime {
|
|
10
|
+
/**
|
|
11
|
+
* Create a ClockTimeTz from a JavaScript Date.
|
|
12
|
+
* @param javascriptDate - A JavaScript Date instance
|
|
13
|
+
* @param options - Optional configuration
|
|
14
|
+
* @param options.zone - Timezone to interpret the date in (IANA timezone name or Zone object)
|
|
15
|
+
* @returns A ClockTimeTz for the time portion
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* ClockTimeTz.fromJSDate(new Date())
|
|
19
|
+
* ClockTimeTz.fromJSDate(new Date(), { zone: 'America/New_York' })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
static fromJSDate(javascriptDate, opts = {}) {
|
|
23
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromJSDate(javascriptDate, opts));
|
|
24
|
+
return new ClockTimeTz(dateTime);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a ClockTimeTz from an ISO 8601 time string.
|
|
28
|
+
* If the string includes timezone information, it will be used.
|
|
29
|
+
* If no timezone is in the string, it will be interpreted as UTC.
|
|
30
|
+
* @param str - ISO time string (e.g., '14:30:45.123456-05:00')
|
|
31
|
+
* @param options - Optional configuration
|
|
32
|
+
* @param options.zone - Timezone to interpret the time in (overrides timezone in string)
|
|
33
|
+
* @returns A ClockTimeTz for the given time
|
|
34
|
+
* @throws {InvalidClockTimeTz} When the ISO string is invalid
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* ClockTimeTz.fromISO('14:30:45.123456') // Interpreted as UTC
|
|
38
|
+
* ClockTimeTz.fromISO('14:30:45.123456-05:00') // Uses timezone from string
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
static fromISO(str, opts = {}) {
|
|
42
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromISO(str, opts));
|
|
43
|
+
return new ClockTimeTz(dateTime);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a ClockTimeTz from an SQL time string.
|
|
47
|
+
* If no zone option is provided, the time will be interpreted as UTC.
|
|
48
|
+
* @param str - SQL time string (e.g., '14:30:45.123456')
|
|
49
|
+
* @param options - Optional configuration
|
|
50
|
+
* @param options.zone - Timezone to interpret the time in (overrides timezone in string)
|
|
51
|
+
* @returns A ClockTimeTz for the given time
|
|
52
|
+
* @throws {InvalidClockTimeTz} When the SQL string is invalid
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* ClockTimeTz.fromSQL('14:30:45.123456') // Interpreted as UTC
|
|
56
|
+
* ClockTimeTz.fromSQL('14:30:45.123456+05:30') // Uses timezone from string
|
|
57
|
+
* ClockTimeTz.fromSQL('14:30:45', { zone: 'America/Chicago' }) // Uses specified zone
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
static fromSQL(str, opts = {}) {
|
|
61
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromSQL(str, opts));
|
|
62
|
+
return new ClockTimeTz(dateTime);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a ClockTimeTz from a custom format string.
|
|
66
|
+
* Uses Luxon format tokens (e.g., 'HH:mm:ss', 'hh:mm a').
|
|
67
|
+
* @param text - The string to parse
|
|
68
|
+
* @param format - Format string using Luxon tokens
|
|
69
|
+
* @param opts - Optional configuration
|
|
70
|
+
* @param opts.zone - Timezone to interpret the time in (IANA timezone name or Zone object)
|
|
71
|
+
* @param opts.locale - Locale for parsing (e.g., 'en-US', 'fr-FR')
|
|
72
|
+
* @param opts.numberingSystem - Numbering system (e.g., 'arab', 'beng')
|
|
73
|
+
* @param opts.outputCalendar - Output calendar system (e.g., 'islamic', 'hebrew')
|
|
74
|
+
* @returns A ClockTimeTz for the parsed time
|
|
75
|
+
* @throws {InvalidClockTimeTz} When the string doesn't match the format or is invalid
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* ClockTimeTz.fromFormat('14:30:45', 'HH:mm:ss')
|
|
79
|
+
* ClockTimeTz.fromFormat('2:30 PM', 'h:mm a')
|
|
80
|
+
* ClockTimeTz.fromFormat('14:30:45 -05:00', 'HH:mm:ss ZZ')
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static fromFormat(text, format, opts) {
|
|
84
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromFormat(text, format, opts));
|
|
85
|
+
return new ClockTimeTz(dateTime);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a ClockTimeTz from an object with time units.
|
|
89
|
+
* @param obj - Object with hour, minute, second, millisecond, microsecond properties
|
|
90
|
+
* @param opts - Optional configuration
|
|
91
|
+
* @param opts.zone - Timezone for the time (IANA timezone name or Zone object, defaults to UTC)
|
|
92
|
+
* @param opts.locale - Locale (e.g., 'en-US', 'fr-FR')
|
|
93
|
+
* @param opts.numberingSystem - Numbering system (e.g., 'arab', 'beng')
|
|
94
|
+
* @param opts.outputCalendar - Output calendar system (e.g., 'islamic', 'hebrew')
|
|
95
|
+
* @returns A ClockTimeTz for the given components
|
|
96
|
+
* @throws {InvalidClockTimeTz} When time values are invalid
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }) // UTC by default
|
|
100
|
+
*
|
|
101
|
+
* // Note for when sending a named, non-UTC time zone, soch as 'America/New_York':
|
|
102
|
+
* // Sending a non-UTC time zone will interpret the time zone based on DateTime.now,
|
|
103
|
+
* // meaning the resulting ClockTimeTz will have a different time and offset when
|
|
104
|
+
* // generated during daylight savings time than not during daylight savings time
|
|
105
|
+
* ClockTimeTz.fromObject({ hour: 14, minute: 30 }, { zone: 'America/New_York' })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
static fromObject(obj, opts) {
|
|
109
|
+
// for ClockTimeTz, we set the date to now because the time in a timezone, like 'America/New_York'
|
|
110
|
+
// is dependent on the date
|
|
111
|
+
const nowObject = DateTime.now(opts?.zone ? { zone: opts.zone } : undefined).toObject();
|
|
112
|
+
const dateTime = this.wrapLuxonError(() => DateTime.fromObject({
|
|
113
|
+
year: nowObject.year,
|
|
114
|
+
month: nowObject.month,
|
|
115
|
+
day: nowObject.day,
|
|
116
|
+
...obj,
|
|
117
|
+
}, opts));
|
|
118
|
+
return new ClockTimeTz(dateTime);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns the time as an ISO 8601 time string with timezone offset.
|
|
122
|
+
* Alias for `toISOTime()`.
|
|
123
|
+
*
|
|
124
|
+
* @param opts - Optional format options
|
|
125
|
+
* @param opts.suppressMilliseconds - If true, omits milliseconds/microseconds when they are zero
|
|
126
|
+
* @param opts.suppressSeconds - If true, omits seconds when they are zero
|
|
127
|
+
* @param opts.format - Format variant: 'basic' (compact) or 'extended' (default, with colons)
|
|
128
|
+
* @returns ISO time string with timezone offset (e.g., '14:30:45.123456-05:00')
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).toISO() // '14:30:45.000000+00:00'
|
|
132
|
+
* ClockTimeTz.fromISO('14:30:45-05:00').toISO() // '14:30:45.000000-05:00'
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
toISO(opts) {
|
|
136
|
+
return this.dateTime.toISOTime({ ...opts, includeOffset: true });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns the SQL time string with timezone offset.
|
|
140
|
+
* Result is memoized for performance.
|
|
141
|
+
*
|
|
142
|
+
* @returns SQL time string with timezone offset (e.g., '14:30:45.123456 -05:00')
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* ClockTimeTz.fromISO('14:30:45-05:00').toSQL() // '14:30:45.000000 -05:00'
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
toSQL() {
|
|
149
|
+
if (this._toSQL)
|
|
150
|
+
return this._toSQL;
|
|
151
|
+
this._toSQL = this.dateTime.toSQLTime({ includeOffset: true });
|
|
152
|
+
return this._toSQL;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Gets the timezone name.
|
|
156
|
+
* @returns The timezone name
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* ClockTimeTz.fromObject({ hour: 14 }, { zone: 'America/New_York' }).zoneName
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
get zoneName() {
|
|
163
|
+
return this.dateTime.zoneName;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets the timezone offset in minutes.
|
|
167
|
+
* @returns The offset in minutes
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* ClockTimeTz.fromISO('14:30:45-05:00').offset // -300
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
get offset() {
|
|
174
|
+
return this.dateTime.offset;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns a ClockTime for the current time.
|
|
178
|
+
* @returns A ClockTime for now
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* ClockTime.now()
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
static now(opts) {
|
|
185
|
+
return new ClockTimeTz(DateTime.now(opts));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns a new ClockTimeTz with the timezone changed.
|
|
189
|
+
* The time value changes to reflect the same instant in the new timezone.
|
|
190
|
+
* @param zone - The timezone to convert to
|
|
191
|
+
* @returns A new ClockTimeTz in the specified timezone
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const utc = ClockTimeTz.fromObject({ hour: 14, minute: 30 }, { zone: 'UTC' })
|
|
195
|
+
* const ny = utc.setZone('America/New_York')
|
|
196
|
+
* // Time is converted to New York timezone (e.g., 09:30 EST)
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
setZone(zone) {
|
|
200
|
+
return new ClockTimeTz(this.dateTime.setZone(zone));
|
|
201
|
+
}
|
|
202
|
+
static wrapLuxonError(fn) {
|
|
203
|
+
try {
|
|
204
|
+
return fn();
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (error instanceof Error)
|
|
208
|
+
throw new InvalidClockTimeTz(error);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
wrapLuxonError(fn) {
|
|
213
|
+
return this.constructor.wrapLuxonError(fn);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Thrown when a ClockTimeTz is invalid (e.g., invalid input or time values).
|
|
218
|
+
* @param error - The original error (available as cause)
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* try {
|
|
222
|
+
* ClockTimeTz.fromISO('25:00:00')
|
|
223
|
+
* } catch (e) {
|
|
224
|
+
* if (e instanceof InvalidClockTimeTz) console.error(e.message)
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export class InvalidClockTimeTz extends Error {
|
|
229
|
+
constructor(error) {
|
|
230
|
+
super((error.message ?? '').replace('DateTime', 'ClockTimeTz'));
|
|
231
|
+
}
|
|
232
|
+
}
|