[lang-ref] ( get_end_of_month ) ( python )

def test_get_end_of_month():
    # calendar.monthrange(y, m)[1]
    def to_date(yyyymmdd):
        return datetime.datetime.strptime(yyyymmdd, r'%Y%m%d').date()

    def get_eom(d):
        last_day = calendar.monthrange(d.year, d.month)[1]
        eom = d.replace(day=last_day)
        return eom

    assert get_eom(to_date('20250101')) == to_date('20250131')
    assert get_eom(to_date('20250205')) == to_date('20250228')
    assert get_eom(to_date('20250131')) == to_date('20250131')
    assert get_eom(to_date('20250228')) == to_date('20250228')