@@ -102,12 +102,87 @@ export class IgxBooleanFilteringOperand extends IgxFilteringOperand {
102
102
}
103
103
}
104
104
105
+ /**
106
+ * @internal
107
+ * @hidden
108
+ */
109
+ class IgxBaseDateTimeFilteringOperand extends IgxFilteringOperand {
110
+ protected constructor ( ) {
111
+ super ( ) ;
112
+ this . operations = [ {
113
+ name : 'empty' ,
114
+ isUnary : true ,
115
+ iconName : 'is-empty' ,
116
+ logic : ( target : Date ) => target === null || target === undefined
117
+ } , {
118
+ name : 'notEmpty' ,
119
+ isUnary : true ,
120
+ iconName : 'not-empty' ,
121
+ logic : ( target : Date ) => target !== null && target !== undefined
122
+ } ] . concat ( this . operations ) ;
123
+ }
124
+
125
+ /**
126
+ * Splits a Date object into parts
127
+ *
128
+ * @memberof IgxDateFilteringOperand
129
+ */
130
+ public static getDateParts ( date : Date , dateFormat ?: string ) : IDateParts {
131
+ const res = {
132
+ day : null ,
133
+ hours : null ,
134
+ milliseconds : null ,
135
+ minutes : null ,
136
+ month : null ,
137
+ seconds : null ,
138
+ year : null
139
+ } ;
140
+ if ( ! date || ! dateFormat ) {
141
+ return res ;
142
+ }
143
+ if ( dateFormat . indexOf ( 'y' ) >= 0 ) {
144
+ res . year = date . getFullYear ( ) ;
145
+ }
146
+ if ( dateFormat . indexOf ( 'M' ) >= 0 ) {
147
+ res . month = date . getMonth ( ) ;
148
+ }
149
+ if ( dateFormat . indexOf ( 'd' ) >= 0 ) {
150
+ res . day = date . getDate ( ) ;
151
+ }
152
+ if ( dateFormat . indexOf ( 'h' ) >= 0 ) {
153
+ res . hours = date . getHours ( ) ;
154
+ }
155
+ if ( dateFormat . indexOf ( 'm' ) >= 0 ) {
156
+ res . minutes = date . getMinutes ( ) ;
157
+ }
158
+ if ( dateFormat . indexOf ( 's' ) >= 0 ) {
159
+ res . seconds = date . getSeconds ( ) ;
160
+ }
161
+ if ( dateFormat . indexOf ( 'f' ) >= 0 ) {
162
+ res . milliseconds = date . getMilliseconds ( ) ;
163
+ }
164
+ return res ;
165
+ }
166
+
167
+ protected findValueInSet ( target : any , searchVal : Set < any > ) {
168
+ if ( ! target ) {
169
+ return false ;
170
+ }
171
+ return searchVal . has ( target . toISOString ( ) ) ;
172
+ }
173
+
174
+ protected validateInputData ( target : Date ) {
175
+ if ( ! ( target instanceof Date ) ) {
176
+ throw new Error ( 'Could not perform filtering on \'date\' column because the datasource object type is not \'Date\'.' ) ;
177
+ }
178
+ }
179
+ }
105
180
/**
106
181
* Provides filtering operations for Dates
107
182
*
108
183
* @export
109
184
*/
110
- export class IgxDateFilteringOperand extends IgxFilteringOperand {
185
+ export class IgxDateFilteringOperand extends IgxBaseDateTimeFilteringOperand {
111
186
protected constructor ( ) {
112
187
super ( ) ;
113
188
this . operations = [ {
@@ -310,73 +385,8 @@ export class IgxDateFilteringOperand extends IgxFilteringOperand {
310
385
const now = IgxDateFilteringOperand . getDateParts ( new Date ( ) , 'y' ) ;
311
386
return d . year === now . year + 1 ;
312
387
}
313
- } , {
314
- name : 'empty' ,
315
- isUnary : true ,
316
- iconName : 'is-empty' ,
317
- logic : ( target : Date ) => target === null || target === undefined
318
- } , {
319
- name : 'notEmpty' ,
320
- isUnary : true ,
321
- iconName : 'not-empty' ,
322
- logic : ( target : Date ) => target !== null && target !== undefined
323
388
} ] . concat ( this . operations ) ;
324
389
}
325
-
326
- /**
327
- * Splits a Date object into parts
328
- *
329
- * @memberof IgxDateFilteringOperand
330
- */
331
- public static getDateParts ( date : Date , dateFormat ?: string ) : IDateParts {
332
- const res = {
333
- day : null ,
334
- hours : null ,
335
- milliseconds : null ,
336
- minutes : null ,
337
- month : null ,
338
- seconds : null ,
339
- year : null
340
- } ;
341
- if ( ! date || ! dateFormat ) {
342
- return res ;
343
- }
344
- if ( dateFormat . indexOf ( 'y' ) >= 0 ) {
345
- res . year = date . getFullYear ( ) ;
346
- }
347
- if ( dateFormat . indexOf ( 'M' ) >= 0 ) {
348
- res . month = date . getMonth ( ) ;
349
- }
350
- if ( dateFormat . indexOf ( 'd' ) >= 0 ) {
351
- res . day = date . getDate ( ) ;
352
- }
353
- if ( dateFormat . indexOf ( 'h' ) >= 0 ) {
354
- res . hours = date . getHours ( ) ;
355
- }
356
- if ( dateFormat . indexOf ( 'm' ) >= 0 ) {
357
- res . minutes = date . getMinutes ( ) ;
358
- }
359
- if ( dateFormat . indexOf ( 's' ) >= 0 ) {
360
- res . seconds = date . getSeconds ( ) ;
361
- }
362
- if ( dateFormat . indexOf ( 'f' ) >= 0 ) {
363
- res . milliseconds = date . getMilliseconds ( ) ;
364
- }
365
- return res ;
366
- }
367
-
368
- protected findValueInSet ( target : any , searchVal : Set < any > ) {
369
- if ( ! target ) {
370
- return false ;
371
- }
372
- return searchVal . has ( target . toISOString ( ) ) ;
373
- }
374
-
375
- protected validateInputData ( target : Date ) {
376
- if ( ! ( target instanceof Date ) ) {
377
- throw new Error ( 'Could not perform filtering on \'date\' column because the datasource object type is not \'Date\'.' ) ;
378
- }
379
- }
380
390
}
381
391
382
392
export class IgxDateTimeFilteringOperand extends IgxDateFilteringOperand {
@@ -426,7 +436,7 @@ export class IgxDateTimeFilteringOperand extends IgxDateFilteringOperand {
426
436
}
427
437
}
428
438
429
- export class IgxTimeFilteringOperand extends IgxFilteringOperand {
439
+ export class IgxTimeFilteringOperand extends IgxBaseDateTimeFilteringOperand {
430
440
protected constructor ( ) {
431
441
super ( ) ;
432
442
this . operations = [ {
@@ -438,8 +448,8 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
438
448
return false ;
439
449
}
440
450
this . validateInputData ( target ) ;
441
- const targetp = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
442
- const searchp = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
451
+ const targetp = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
452
+ const searchp = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
443
453
return targetp . hours === searchp . hours &&
444
454
targetp . minutes === searchp . minutes &&
445
455
targetp . seconds === searchp . seconds ;
@@ -453,8 +463,8 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
453
463
return true ;
454
464
}
455
465
this . validateInputData ( target ) ;
456
- const targetp = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
457
- const searchp = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
466
+ const targetp = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
467
+ const searchp = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
458
468
return targetp . hours !== searchp . hours ||
459
469
targetp . minutes !== searchp . minutes ||
460
470
targetp . seconds !== searchp . seconds ;
@@ -469,8 +479,8 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
469
479
}
470
480
471
481
this . validateInputData ( target ) ;
472
- const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
473
- const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
482
+ const targetn = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
483
+ const search = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
474
484
475
485
return targetn . hours < search . hours ? true : targetn . hours === search . hours && targetn . minutes < search . minutes ?
476
486
true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds < search . seconds ;
@@ -485,8 +495,8 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
485
495
}
486
496
487
497
this . validateInputData ( target ) ;
488
- const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
489
- const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
498
+ const targetn = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
499
+ const search = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
490
500
491
501
return targetn . hours > search . hours ? true : targetn . hours === search . hours && targetn . minutes > search . minutes ?
492
502
true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds > search . seconds ;
@@ -501,8 +511,8 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
501
511
}
502
512
503
513
this . validateInputData ( target ) ;
504
- const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
505
- const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
514
+ const targetn = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
515
+ const search = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
506
516
return ( targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds === search . seconds ) ||
507
517
targetn . hours < search . hours ? true : targetn . hours === search . hours && targetn . minutes < search . minutes ?
508
518
true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds < search . seconds ;
@@ -517,37 +527,20 @@ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
517
527
}
518
528
519
529
this . validateInputData ( target ) ;
520
- const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
521
- const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
530
+ const targetn = IgxTimeFilteringOperand . getDateParts ( target , 'hms' ) ;
531
+ const search = IgxTimeFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
522
532
return ( targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds === search . seconds ) ||
523
533
targetn . hours > search . hours ? true : targetn . hours === search . hours && targetn . minutes > search . minutes ?
524
534
true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds > search . seconds ;
525
535
}
526
- } , {
527
- name : 'empty' ,
528
- isUnary : true ,
529
- iconName : 'is-empty' ,
530
- logic : ( target : Date ) => target === null || target === undefined
531
- } , {
532
- name : 'notEmpty' ,
533
- isUnary : true ,
534
- iconName : 'not-empty' ,
535
- logic : ( target : Date ) => target !== null && target !== undefined
536
536
} ] . concat ( this . operations ) ;
537
537
}
538
538
539
-
540
539
protected findValueInSet ( target : any , searchVal : Set < any > ) {
541
540
if ( ! target ) {
542
541
return false ;
543
542
}
544
- return searchVal . has ( target ) ;
545
- }
546
-
547
- protected validateInputData ( target : Date ) {
548
- if ( ! ( target instanceof Date ) ) {
549
- throw new Error ( 'Could not perform filtering on \'date\' column because the datasource object type is not \'Date\'.' ) ;
550
- }
543
+ return searchVal . has ( target . toLocaleTimeString ( ) ) ;
551
544
}
552
545
}
553
546
0 commit comments