@@ -584,6 +584,115 @@ 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 : [
619
+ { t : + new Date ( '2018-01-08 05:14:23.234' ) , y : 10 } ,
620
+ { t : + new Date ( '2018-01-09 06:17:43.426' ) , y : 3 }
621
+ ]
622
+ } ] ,
623
+ } ,
624
+ options : {
625
+ scales : {
626
+ xAxes : [ {
627
+ id : 'xScale0' ,
628
+ type : 'time' ,
629
+ position : 'bottom'
630
+ } ] ,
631
+ }
632
+ }
633
+ } ) ;
634
+
635
+ var xScale = chart . scales . xScale0 ;
636
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
637
+ expect ( label ) . toEqual ( 'Jan 8, 2018 5:14:23.234 am' ) ;
638
+ } ) ;
639
+
640
+ it ( 'should get the correct label for a timestamp with time' , function ( ) {
641
+ var chart = window . acquireChart ( {
642
+ type : 'line' ,
643
+ data : {
644
+ datasets : [ {
645
+ xAxisID : 'xScale0' ,
646
+ data : [
647
+ { t : + new Date ( '2018-01-08 05:14:23' ) , y : 10 } ,
648
+ { t : + new Date ( '2018-01-09 06:17:43' ) , y : 3 }
649
+ ]
650
+ } ] ,
651
+ } ,
652
+ options : {
653
+ scales : {
654
+ xAxes : [ {
655
+ id : 'xScale0' ,
656
+ type : 'time' ,
657
+ position : 'bottom'
658
+ } ] ,
659
+ }
660
+ }
661
+ } ) ;
662
+
663
+ var xScale = chart . scales . xScale0 ;
664
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
665
+ expect ( label ) . toEqual ( 'Jan 8, 2018 5:14:23 am' ) ;
666
+ } ) ;
667
+
668
+ it ( 'should get the correct label for a timestamp representing a date' , function ( ) {
669
+ var chart = window . acquireChart ( {
670
+ type : 'line' ,
671
+ data : {
672
+ datasets : [ {
673
+ xAxisID : 'xScale0' ,
674
+ data : [
675
+ { t : + new Date ( '2018-01-08 00:00:00' ) , y : 10 } ,
676
+ { t : + new Date ( '2018-01-09 00:00:00' ) , y : 3 }
677
+ ]
678
+ } ] ,
679
+ } ,
680
+ options : {
681
+ scales : {
682
+ xAxes : [ {
683
+ id : 'xScale0' ,
684
+ type : 'time' ,
685
+ position : 'bottom'
686
+ } ] ,
687
+ }
688
+ }
689
+ } ) ;
690
+
691
+ var xScale = chart . scales . xScale0 ;
692
+ var label = xScale . getLabelForIndex ( 0 , 0 ) ;
693
+ expect ( label ) . toEqual ( 'Jan 8, 2018' ) ;
694
+ } ) ;
695
+
587
696
it ( 'should get the correct pixel for only one data in the dataset' , function ( ) {
588
697
var chart = window . acquireChart ( {
589
698
type : 'line' ,
0 commit comments