@@ -584,6 +584,119 @@ 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 label0 = xScale . getLabelForIndex ( 0 , 0 ) ;
634
+ // check things that won't differ by timezone until we have timezone support
635
+ expect ( label0 ) . toBeTruthy ( ) ;
636
+ expect ( label0 ) . toContain ( 'Jan' ) ;
637
+ expect ( label0 ) . toContain ( '2018' ) ;
638
+ expect ( label0 ) . toContain ( '44:17.180' ) ;
639
+ expect ( label0 ) . toContain ( 'm' ) ;
640
+ } ) ;
641
+
642
+ it ( 'should get the correct label for a timestamp with time' , function ( ) {
643
+ var chart = window . acquireChart ( {
644
+ type : 'line' ,
645
+ data : {
646
+ datasets : [ {
647
+ xAxisID : 'xScale0' ,
648
+ data : [ { t : 1515469457000 , y : 10 } , { t : 1515469458000 , y : 3 } ]
649
+ } ] ,
650
+ } ,
651
+ options : {
652
+ scales : {
653
+ xAxes : [ {
654
+ id : 'xScale0' ,
655
+ type : 'time' ,
656
+ position : 'bottom'
657
+ } ] ,
658
+ }
659
+ }
660
+ } ) ;
661
+
662
+ var xScale = chart . scales . xScale0 ;
663
+ var label0 = xScale . getLabelForIndex ( 0 , 0 ) ;
664
+ // check things that won't differ by timezone until we have timezone support
665
+ expect ( label0 ) . toBeTruthy ( ) ;
666
+ expect ( label0 ) . toContain ( 'Jan' ) ;
667
+ expect ( label0 ) . toContain ( '2018' ) ;
668
+ expect ( label0 ) . not . toContain ( '.000' ) ;
669
+ } ) ;
670
+
671
+ it ( 'should get the correct label for a timestamp representing a date' , function ( ) {
672
+ var chart = window . acquireChart ( {
673
+ type : 'line' ,
674
+ data : {
675
+ datasets : [ {
676
+ xAxisID : 'xScale0' ,
677
+ data : [ { t : 1515484800000 , y : 10 } , { t : 1515571200000 , y : 3 } ]
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 label0 = xScale . getLabelForIndex ( 0 , 0 ) ;
693
+ // check things that won't differ by timezone until we have timezone support
694
+ expect ( label0 ) . toBeTruthy ( ) ;
695
+ expect ( label0 ) . toContain ( 'Jan' ) ;
696
+ expect ( label0 ) . toContain ( '2018' ) ;
697
+ expect ( label0 ) . not . toContain ( '.000' ) ;
698
+ } ) ;
699
+
587
700
it ( 'should get the correct pixel for only one data in the dataset' , function ( ) {
588
701
var chart = window . acquireChart ( {
589
702
type : 'line' ,
0 commit comments