from datetime import datetime


def convert_date(raw_date):
    """
    Convert raw date field into a value interpretable by the dataserver.

    The date is listed in YYYY-mm-dd HH:MM:SS format, but the date filtering API
    expects mm/dd/YYYYZ format.
    """
    date = datetime.strptime(raw_date, "%Y-%m-%d %H:%M:%S")
    # Some cases are reported using the Buddhist calendar which is 543 years ahead of the Gregorian
    year = date.year
    if year > 2540:
        corrected_year = year - 543
        return date.strftime(f"%m/%d/{corrected_year}Z")
    else:
        return date.strftime("%m/%d/%YZ")