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