from datetime import date
from time import strptime
    
def convert(segment, row, log):
    if row['eventdate1x'] is None:
        row['eventyr'], row['eventmo'], row['eventda'] = 9999, 99, 99
    else:
        try:
            v = row['eventdate1x'].replace('-', '')
            assert(len(v) == 8)
            assert(1850 <= int(value[:4]) <= date.today().year)
            dt = strptime(v, '%Y%m%d')
            row['eventyr'], row['eventmo'], row['eventda'] = dt[0], dt[1], dt[2]
        except:
            row['eventyr'], row['eventmo'], row['eventda'] = 9999, 99, 99
    
    if segment == 'arrest':
        if row['adispdatex'] is None:
            row['adspyr'], row['adspmo'], row['adspda'] = 9999, 99, 99
        else:
            try:
                v = row['adispdatex'].replace('-', '')
                assert(len(v) == 8)
                assert(1850 <= int(value[:4]) <= date.today().year)
                dt = strptime(v, '%Y%m%d')
                row['adspyr'], row['adspmo'], row['adspda'] = dt[0], dt[1], dt[2]
            except:
                row['adspyr'], row['adspmo'], row['adspda'] = 9999, 99, 99
        
        
    