function date_time = case_time(time_str, line_datestr)

yr=str2num(line_datestr(1:4));
mo=str2num(line_datestr(5:6));
dy=str2num(line_datestr(7:8));
hr=str2num(line_datestr(9:10));
mn=str2num(line_datestr(11:12));

 
switch length(time_str)
    case 2
       current_min=str2num(time_str);
       if current_min>mn
            hr2=hr-1;
            if hr2<0
                hr2=hr2+24;
                date_time=datenum(yr,mo,dy,hr2,current_min,0)-1;
            else
                date_time=datenum(yr,mo,dy,hr2,current_min,0);
            end
       else
           hr2=hr;
           date_time=datenum(yr,mo,dy,hr2,current_min,0);
       end
    case 4
        hr2=str2num(time_str(1:2));
        current_min=str2num(time_str(3:4));
        if hr2>hr
            date_time = datenum(yr,mo,dy,hr2,current_min,0)-1;
        else
            date_time = datenum(yr,mo,dy,hr2,current_min,0);
        end                   
    otherwise
        current_min = [];
        date_time=datenum(yr,mo,dy,hr,mn,0);
end
