@@ -372,7 +372,220 @@ export class IgxDateFilteringOperand extends IgxFilteringOperand {
372
372
return searchVal . has ( target . toISOString ( ) ) ;
373
373
}
374
374
375
- private validateInputData ( target : Date ) {
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
+ }
381
+
382
+ export class IgxDateTimeFilteringOperand extends IgxDateFilteringOperand {
383
+ protected constructor ( ) {
384
+ super ( ) ;
385
+ let index = this . operations . indexOf ( this . condition ( 'equals' ) ) ;
386
+ this . operations . splice ( index , 1 ) ;
387
+ index = this . operations . indexOf ( this . condition ( 'doesNotEqual' ) ) ;
388
+ this . operations . splice ( index , 1 ) ;
389
+ this . operations = [ {
390
+ name : 'equals' ,
391
+ isUnary : false ,
392
+ iconName : 'equals' ,
393
+ logic : ( target : Date , searchVal : Date ) => {
394
+ if ( ! target ) {
395
+ return false ;
396
+ }
397
+ this . validateInputData ( target ) ;
398
+ const targetp = IgxDateTimeFilteringOperand . getDateParts ( target , 'yMdhms' ) ;
399
+ const searchp = IgxDateTimeFilteringOperand . getDateParts ( searchVal , 'yMdhms' ) ;
400
+ return targetp . year === searchp . year &&
401
+ targetp . month === searchp . month &&
402
+ targetp . day === searchp . day &&
403
+ targetp . hours === searchp . hours &&
404
+ targetp . minutes === searchp . minutes &&
405
+ targetp . seconds === searchp . seconds ;
406
+ }
407
+ } , {
408
+ name : 'doesNotEqual' ,
409
+ isUnary : false ,
410
+ iconName : 'not-equal' ,
411
+ logic : ( target : Date , searchVal : Date ) => {
412
+ if ( ! target ) {
413
+ return true ;
414
+ }
415
+ this . validateInputData ( target ) ;
416
+ const targetp = IgxDateTimeFilteringOperand . getDateParts ( target , 'yMdhms' ) ;
417
+ const searchp = IgxDateTimeFilteringOperand . getDateParts ( searchVal , 'yMdhms' ) ;
418
+ return targetp . year !== searchp . year ||
419
+ targetp . month !== searchp . month ||
420
+ targetp . day !== searchp . day ||
421
+ targetp . hours !== searchp . hours ||
422
+ targetp . minutes !== searchp . minutes ||
423
+ targetp . seconds !== searchp . seconds ;
424
+ }
425
+ } ] . concat ( this . operations ) ;
426
+ }
427
+ }
428
+
429
+ export class IgxTimeFilteringOperand extends IgxFilteringOperand {
430
+ protected constructor ( ) {
431
+ super ( ) ;
432
+ this . operations = [ {
433
+ name : 'at' ,
434
+ isUnary : false ,
435
+ iconName : 'equals' ,
436
+ logic : ( target : Date , searchVal : Date ) => {
437
+ if ( ! target ) {
438
+ return false ;
439
+ }
440
+ this . validateInputData ( target ) ;
441
+ const targetp = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
442
+ const searchp = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
443
+ return targetp . hours === searchp . hours &&
444
+ targetp . minutes === searchp . minutes &&
445
+ targetp . seconds === searchp . seconds ;
446
+ }
447
+ } , {
448
+ name : 'not_at' ,
449
+ isUnary : false ,
450
+ iconName : 'not-equal' ,
451
+ logic : ( target : Date , searchVal : Date ) => {
452
+ if ( ! target ) {
453
+ return true ;
454
+ }
455
+ this . validateInputData ( target ) ;
456
+ const targetp = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
457
+ const searchp = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
458
+ return targetp . hours !== searchp . hours ||
459
+ targetp . minutes !== searchp . minutes ||
460
+ targetp . seconds !== searchp . seconds ;
461
+ }
462
+ } , {
463
+ name : 'before' ,
464
+ isUnary : false ,
465
+ iconName : 'is-before' ,
466
+ logic : ( target : Date , searchVal : Date ) => {
467
+ if ( ! target ) {
468
+ return false ;
469
+ }
470
+
471
+ this . validateInputData ( target ) ;
472
+ const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
473
+ const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
474
+
475
+ return targetn . hours < search . hours ? true : targetn . hours === search . hours && targetn . minutes < search . minutes ?
476
+ true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds < search . seconds ;
477
+ }
478
+ } , {
479
+ name : 'after' ,
480
+ isUnary : false ,
481
+ iconName : 'is-after' ,
482
+ logic : ( target : Date , searchVal : Date ) => {
483
+ if ( ! target ) {
484
+ return false ;
485
+ }
486
+
487
+ this . validateInputData ( target ) ;
488
+ const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
489
+ const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
490
+
491
+ return targetn . hours > search . hours ? true : targetn . hours === search . hours && targetn . minutes > search . minutes ?
492
+ true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds > search . seconds ;
493
+ }
494
+ } , {
495
+ name : 'at_before' ,
496
+ isUnary : false ,
497
+ iconName : 'is-before' ,
498
+ logic : ( target : Date , searchVal : Date ) => {
499
+ if ( ! target ) {
500
+ return false ;
501
+ }
502
+
503
+ this . validateInputData ( target ) ;
504
+ const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
505
+ const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
506
+ return ( targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds === search . seconds ) ||
507
+ targetn . hours < search . hours ? true : targetn . hours === search . hours && targetn . minutes < search . minutes ?
508
+ true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds < search . seconds ;
509
+ }
510
+ } , {
511
+ name : 'at_after' ,
512
+ isUnary : false ,
513
+ iconName : 'is-after' ,
514
+ logic : ( target : Date , searchVal : Date ) => {
515
+ if ( ! target ) {
516
+ return false ;
517
+ }
518
+
519
+ this . validateInputData ( target ) ;
520
+ const targetn = IgxDateFilteringOperand . getDateParts ( target , 'hms' ) ;
521
+ const search = IgxDateFilteringOperand . getDateParts ( searchVal , 'hms' ) ;
522
+ return ( targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds === search . seconds ) ||
523
+ targetn . hours > search . hours ? true : targetn . hours === search . hours && targetn . minutes > search . minutes ?
524
+ true : targetn . hours === search . hours && targetn . minutes === search . minutes && targetn . seconds > search . seconds ;
525
+ }
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
+ } ] . concat ( this . operations ) ;
537
+ }
538
+
539
+ /**
540
+ * Splits a Date object into parts
541
+ *
542
+ * @memberof IgxDateFilteringOperand
543
+ */
544
+ public static getDateParts ( date : Date , dateFormat ?: string ) : IDateParts {
545
+ const res = {
546
+ day : null ,
547
+ hours : null ,
548
+ milliseconds : null ,
549
+ minutes : null ,
550
+ month : null ,
551
+ seconds : null ,
552
+ year : null
553
+ } ;
554
+ if ( ! date || ! dateFormat ) {
555
+ return res ;
556
+ }
557
+ if ( dateFormat . indexOf ( 'y' ) >= 0 ) {
558
+ res . year = date . getFullYear ( ) ;
559
+ }
560
+ if ( dateFormat . indexOf ( 'M' ) >= 0 ) {
561
+ res . month = date . getMonth ( ) ;
562
+ }
563
+ if ( dateFormat . indexOf ( 'd' ) >= 0 ) {
564
+ res . day = date . getDate ( ) ;
565
+ }
566
+ if ( dateFormat . indexOf ( 'h' ) >= 0 ) {
567
+ res . hours = date . getHours ( ) ;
568
+ }
569
+ if ( dateFormat . indexOf ( 'm' ) >= 0 ) {
570
+ res . minutes = date . getMinutes ( ) ;
571
+ }
572
+ if ( dateFormat . indexOf ( 's' ) >= 0 ) {
573
+ res . seconds = date . getSeconds ( ) ;
574
+ }
575
+ if ( dateFormat . indexOf ( 'f' ) >= 0 ) {
576
+ res . milliseconds = date . getMilliseconds ( ) ;
577
+ }
578
+ return res ;
579
+ }
580
+
581
+ protected findValueInSet ( target : any , searchVal : Set < any > ) {
582
+ if ( ! target ) {
583
+ return false ;
584
+ }
585
+ return searchVal . has ( target . toISOString ( ) ) ;
586
+ }
587
+
588
+ protected validateInputData ( target : Date ) {
376
589
if ( ! ( target instanceof Date ) ) {
377
590
throw new Error ( 'Could not perform filtering on \'date\' column because the datasource object type is not \'Date\'.' ) ;
378
591
}
0 commit comments