@@ -511,6 +511,49 @@ def _create_auto_date_locator(date1, date2):
511
511
assert strings == expected
512
512
513
513
514
+ def test_concise_formatter_tz ():
515
+ def _create_auto_date_locator (date1 , date2 , tz ):
516
+ fig , ax = plt .subplots ()
517
+
518
+ locator = mdates .AutoDateLocator (interval_multiples = True )
519
+ formatter = mdates .ConciseDateFormatter (locator , tz = tz )
520
+ ax .yaxis .set_major_locator (locator )
521
+ ax .yaxis .set_major_formatter (formatter )
522
+ ax .set_ylim (date1 , date2 )
523
+ fig .canvas .draw ()
524
+ sts = []
525
+ for st in ax .get_yticklabels ():
526
+ sts += [st .get_text ()]
527
+ return sts , ax .yaxis .get_offset_text ().get_text ()
528
+
529
+ d1 = datetime .datetime (1997 , 1 , 1 ).replace (tzinfo = datetime .timezone .utc )
530
+ results = ([datetime .timedelta (hours = 40 ),
531
+ ['03:00' , '07:00' , '11:00' , '15:00' , '19:00' , '23:00' ,
532
+ '03:00' , '07:00' , '11:00' , '15:00' , '19:00' ],
533
+ "1997-Jan-02"
534
+ ],
535
+ [datetime .timedelta (minutes = 20 ),
536
+ ['03:00' , '03:05' , '03:10' , '03:15' , '03:20' ],
537
+ "1997-Jan-01"
538
+ ],
539
+ [datetime .timedelta (seconds = 40 ),
540
+ ['03:00' , '05' , '10' , '15' , '20' , '25' , '30' , '35' , '40' ],
541
+ "1997-Jan-01 03:00"
542
+ ],
543
+ [datetime .timedelta (seconds = 2 ),
544
+ ['59.5' , '03:00' , '00.5' , '01.0' , '01.5' , '02.0' , '02.5' ],
545
+ "1997-Jan-01 03:00"
546
+ ],
547
+ )
548
+
549
+ new_tz = datetime .timezone (datetime .timedelta (hours = 3 ))
550
+ for t_delta , expected_strings , expected_offset in results :
551
+ d2 = d1 + t_delta
552
+ strings , offset = _create_auto_date_locator (d1 , d2 , new_tz )
553
+ assert strings == expected_strings
554
+ assert offset == expected_offset
555
+
556
+
514
557
def test_auto_date_locator_intmult_tz ():
515
558
def _create_auto_date_locator (date1 , date2 , tz ):
516
559
locator = mdates .AutoDateLocator (interval_multiples = True , tz = tz )
0 commit comments