@statezero/core 0.1.77 → 0.1.79
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.
|
@@ -72,10 +72,10 @@ function processFieldPath(fieldPath, value, ModelClass, options = {}) {
|
|
|
72
72
|
'exact', 'iexact', 'contains', 'icontains', 'startswith',
|
|
73
73
|
'istartswith', 'endswith', 'iendswith', 'in', 'gt', 'gte',
|
|
74
74
|
'lt', 'lte', 'isnull', 'regex', 'iregex', 'year', 'month',
|
|
75
|
-
'day', 'week_day', 'hour', 'minute', 'second'
|
|
75
|
+
'day', 'week_day', 'hour', 'minute', 'second', 'date', 'time'
|
|
76
76
|
];
|
|
77
77
|
// Date part lookups that can be followed by comparison lookups
|
|
78
|
-
const dateParts = ['year', 'month', 'day', 'week_day', 'hour', 'minute', 'second'];
|
|
78
|
+
const dateParts = ['year', 'month', 'day', 'week_day', 'hour', 'minute', 'second', 'date', 'time'];
|
|
79
79
|
// Comparison lookups that can follow date parts
|
|
80
80
|
const comparisonLookups = ['gt', 'gte', 'lt', 'lte', 'exact'];
|
|
81
81
|
let lookupChain = [];
|
|
@@ -231,7 +231,7 @@ function createOperatorFromLookup(field, lookup, value, isRelationship, ModelCla
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
// Handle date-related lookups
|
|
234
|
-
if (['year', 'month', 'day', 'week_day', 'hour', 'minute', 'second'].includes(lookup)) {
|
|
234
|
+
if (['year', 'month', 'day', 'week_day', 'hour', 'minute', 'second', 'date', 'time'].includes(lookup)) {
|
|
235
235
|
// For date part lookups, we'll use a custom operation
|
|
236
236
|
return {
|
|
237
237
|
field,
|
|
@@ -380,6 +380,55 @@ function createDateOperations(timezone = 'UTC') {
|
|
|
380
380
|
const second = getDatePart(value, dt => dt.second);
|
|
381
381
|
return second !== null && second === params;
|
|
382
382
|
}, ownerQuery, options);
|
|
383
|
+
},
|
|
384
|
+
// Date - extract date portion (ignore time)
|
|
385
|
+
$date(params, ownerQuery, options) {
|
|
386
|
+
return createEqualsOperation((value) => {
|
|
387
|
+
if (!value)
|
|
388
|
+
return false;
|
|
389
|
+
const dateValue = value instanceof Date ? value : new Date(value);
|
|
390
|
+
if (isNaN(dateValue.getTime()))
|
|
391
|
+
return false;
|
|
392
|
+
// Convert both to timezone and get date portions
|
|
393
|
+
const luxonDate = DateTime.fromJSDate(dateValue).setZone(timezone);
|
|
394
|
+
const paramDate = DateTime.fromJSDate(new Date(params)).setZone(timezone);
|
|
395
|
+
// Compare year, month, and day
|
|
396
|
+
return luxonDate.year === paramDate.year &&
|
|
397
|
+
luxonDate.month === paramDate.month &&
|
|
398
|
+
luxonDate.day === paramDate.day;
|
|
399
|
+
}, ownerQuery, options);
|
|
400
|
+
},
|
|
401
|
+
// Time - extract time portion (ignore date)
|
|
402
|
+
$time(params, ownerQuery, options) {
|
|
403
|
+
return createEqualsOperation((value) => {
|
|
404
|
+
if (!value)
|
|
405
|
+
return false;
|
|
406
|
+
const dateValue = value instanceof Date ? value : new Date(value);
|
|
407
|
+
if (isNaN(dateValue.getTime()))
|
|
408
|
+
return false;
|
|
409
|
+
// Convert to timezone
|
|
410
|
+
const luxonDate = DateTime.fromJSDate(dateValue).setZone(timezone);
|
|
411
|
+
// Parse the time string (format: "HH:MM:SS" or a Date object)
|
|
412
|
+
let paramHour, paramMinute, paramSecond;
|
|
413
|
+
if (typeof params === 'string') {
|
|
414
|
+
// Parse time string like "10:30:45"
|
|
415
|
+
const timeParts = params.split(':');
|
|
416
|
+
paramHour = parseInt(timeParts[0], 10);
|
|
417
|
+
paramMinute = parseInt(timeParts[1], 10);
|
|
418
|
+
paramSecond = parseInt(timeParts[2], 10);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
// If it's a Date object, extract time parts
|
|
422
|
+
const paramDate = DateTime.fromJSDate(new Date(params)).setZone(timezone);
|
|
423
|
+
paramHour = paramDate.hour;
|
|
424
|
+
paramMinute = paramDate.minute;
|
|
425
|
+
paramSecond = paramDate.second;
|
|
426
|
+
}
|
|
427
|
+
// Compare hour, minute, and second
|
|
428
|
+
return luxonDate.hour === paramHour &&
|
|
429
|
+
luxonDate.minute === paramMinute &&
|
|
430
|
+
luxonDate.second === paramSecond;
|
|
431
|
+
}, ownerQuery, options);
|
|
383
432
|
}
|
|
384
433
|
};
|
|
385
434
|
// Define part extractors for each date part with Django compatibility
|
|
@@ -390,7 +439,9 @@ function createDateOperations(timezone = 'UTC') {
|
|
|
390
439
|
'week_day': (dt) => dt.weekday === 7 ? 1 : dt.weekday + 1, // Convert to Django's format
|
|
391
440
|
'hour': (dt) => dt.hour,
|
|
392
441
|
'minute': (dt) => dt.minute,
|
|
393
|
-
'second': (dt) => dt.second
|
|
442
|
+
'second': (dt) => dt.second,
|
|
443
|
+
'date': (dt) => dt.toISODate(),
|
|
444
|
+
'time': (dt) => dt.hour * 3600 + dt.minute * 60 + dt.second
|
|
394
445
|
};
|
|
395
446
|
// Generate comparison operations for each date part (year_gt, month_lt, etc.)
|
|
396
447
|
const datePartComparisons = ['gt', 'gte', 'lt', 'lte', 'exact'];
|
package/package.json
CHANGED