8000 Added timezone test for ConciseDateFormatter · matplotlib/matplotlib@c4b747a · GitHub
[go: up one dir, main page]

Skip to content

Commit c4b747a

Browse files
committed
Added timezone test for ConciseDateFormatter
1 parent cd72f05 commit c4b747a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

lib/matplotlib/tests/test_dates.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,68 @@ def _create_auto_date_locator(date1, date2):
511511
assert strings == expected
512512

513513

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(weeks=52 * 200),
531+
[str(t) for t in range(1980, 2201, 20)],
532+
""
533+
],
534+
[datetime.timedelta(weeks=52),
535+
['1997', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
536+
'Sep', 'Oct', 'Nov', 'Dec'],
537+
"1997"
538+
],
539+
[datetime.timedelta(days=141),
540+
['Jan', '22', 'Feb', '22', 'Mar', '22', 'Apr', '22',
541+
'May', '22'],
542+
"1997-May"
543+
],
544+
[datetime.timedelta(days=40),
545+
['Jan', '05', '09', '13', '17', '21', '25', '29', 'Feb',
546+
'05', '09'],
547+
"1997-Feb"
548+
],
549+
[datetime.timedelta(hours=40),
550+
['03:00', '07:00', '11:00', '15:00', '19:00', '23:00',
551+
'03:00', '07:00', '11:00', '15:00', '19:00'],
552+
"1997-Jan-02"
553+
],
554+
[datetime.timedelta(minutes=20),
555+
['03:00', '03:05', '03:10', '03:15', '03:20'],
556+
"1997-Jan-01"
557+
],
558+
[datetime.timedelta(seconds=40),
559+
['03:00', '05', '10', '15', '20', '25', '30', '35', '40'],
560+
"1997-Jan-01 03:00"
561+
],
562+
[datetime.timedelta(seconds=2),
563+
['59.5', '03:00', '00.5', '01.0', '01.5', '02.0', '02.5'],
564+
"1997-Jan-01 03:00"
565+
],
566+
)
567+
568+
new_tz = datetime.timezone(datetime.timedelta(hours=3))
569+
for t_delta, expected_strings, expected_offset in results:
570+
d2 = d1 + t_delta
571+
strings, offset = _create_auto_date_locator(d1, d2, new_tz)
572+
assert strings == expected_strings
573+
assert offset == expected_offset
574+
575+
514576
def test_auto_date_locator_intmult_tz():
515577
def _create_auto_date_locator(date1, date2, tz):
516578
locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)

0 commit comments

Comments
 (0)
0