@@ -584,6 +584,112 @@ describe('Time scale tests', function() {
584
584
expect ( xScale . getLabelForIndex ( 6 , 0 ) ) . toBe ( '2015-01-10T12:00' ) ;
585
585
} ) ;
586
586
587
+ it ( 'should get the correct label when time is specified as a string' , function ( ) {
588
+ var chart = window . acquireChart ( {
589
+ type : 'line' ,
590
+ data : {
591
+ datasets : [ {
592
+ xAxisID : 'xScale0' ,
593
+ data : [ { t : '2015-01-01T20:00:00' , y : 10 } , { t : '2015-01-02T21:00:00' , y : 3 } ]
594
+ } ] ,
595
+ } ,
596
+ options : {
597
+ scales : {
598
+ xAxes : [ {
599
+ id : 'xScale0' ,
600
+ type : 'time' ,
601
+ position : 'bottom'
602
+ } ] ,
603
+ }
604
+ }
605
+ } ) ;
606
+
607
+ var xScale = chart . scales . xScale0 ;
608
+ expect ( xScale . getLabelForIndex ( 0 , 0 ) ) . toBeTruthy ( ) ;
609
+ expect ( xScale . getLabelForIndex ( 0 , 0 ) ) . toBe ( '2015-01-01T20:00:00' ) ;
610
+ } ) ;
611
+
612
+ it ( 'should get the correct label for a timestamp with milliseconds' , function ( ) {
613
+ var chart = window . acquireChart ( {
614
+ type : 'line' ,
615
+ data : {
616
+ datasets : [ {
617
+ xAxisID : 'xScale0' ,
618
+ data : [ { t : 1515469457180 , y : 10 } , { t : 1515469458180 , y : 3 } ]
619
+ } ] ,
620
+ } ,
621
+ options : {
622
+ scales : {
623
+ xAxes : [ {
624
+ id : 'xScale0' ,
625
+ type : 'time' ,
626
+ position : 'bottom'
627
+ } ] ,
628
+ }
629
+ }
630
+ } ) ;
631
+
632
+ var xScale = chart . scales . xScale0 ;
633
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
634
+ expect ( label ) . toMatch ( / ^ J a n \d + , 2 0 1 8 \d { 1 , 2 } : \d { 2 } : \d { 2 } .\d { 3 } ( a m | p m ) $ / ) ;
635
+ } ) ;
636
+
637
+ it ( 'should get the correct label for a timestamp with time' , function ( ) {
638
+ var chart = window . acquireChart ( {
639
+ type : 'line' ,
640
+ data : {
641
+ datasets : [ {
642
+ xAxisID : 'xScale0' ,
643
+ data : [
644
+ { t : + new Date ( '2018-01-08 05:14:23' ) , y : 10 } ,
645
+ { t : + new Date ( '2018-01-09 06:17:43' ) , y : 3 }
646
+ ]
647
+ } ] ,
648
+ } ,
649
+ options : {
650
+ scales : {
651
+ xAxes : [ {
652
+ id : 'xScale0' ,
653
+ type : 'time' ,
654
+ position : 'bottom'
655
+ } ] ,
656
+ }
657
+ }
658
+ } ) ;
659
+
660
+ var xScale = chart . scales . xScale0 ;
661
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
662
+ expect ( label ) . toMatch ( / ^ J a n \d + , 2 0 1 8 \d { 1 , 2 } : \d { 2 } : \d { 2 } ( a m | p m ) $ / ) ;
663
+ } ) ;
664
+
665
+ it ( 'should get the correct label for a timestamp representing a date' , function ( ) {
666
+ var chart = window . acquireChart ( {
667
+ type : 'line' ,
668
+ data : {
669
+ datasets : [ {
670
+ xAxisID : 'xScale0' ,
671
+ data : [
672
+ { t : + new Date ( '2018-01-08 00:00:00' ) , y : 10 } ,
673
+ { t : + new Date ( '2018-01-09 00:00:00' ) , y : 3 }
674
+ ]
675
+ } ] ,
676
+ } ,
677
+ options : {
678
+ scales : {
679
+ xAxes : [ {
680
+ id : 'xScale0' ,
681
+ type : 'time' ,
682
+ position : 'bottom'
683
+ } ] ,
684
+ }
685
+ }
686
+ } ) ;
687
+
688
+ var xScale = chart . scales . xScale0 ;
689
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
690
+ expect ( label ) . toMatch ( / ^ J a n \d + , 2 0 1 8 $ / ) ;
691
+ } ) ;
692
+
587
693
it ( 'should get the correct pixel for only one data in the dataset' , function ( ) {
588
694
var chart = window . acquireChart ( {
589
695
type : 'line' ,
0 commit comments