function [B,E] = matchBE(B_date_time,E_date_time,MW_B_date_time,MW_E_date_time)

D_min = 0.25/24; % minimum thunderstorm duration of 15 min

for i= 1:length(MW_B_date_time)
    % determine the ith begining time:
    if i == 1
         a = find(B_date_time>(MW_B_date_time(i)-(1/24)) & B_date_time<MW_B_date_time(i));
    else
         a = find(B_date_time>max([MW_B_date_time(i)-(1/24) E(i-1)]) & B_date_time<MW_B_date_time(i));
    end
    if  length(a)>=1 
        B(i) = B_date_time(a(1));
    else
        B(i) = MW_B_date_time(i);
    end
    
    % determine the ith ending time
    ind = find(E_date_time>B(i) & E_date_time<MW_E_date_time(i));
    if length(ind)>= 1
        E(i) = E_date_time(ind(end));       
    else
        E(i) = MW_E_date_time(i);
    end
    if E(i)-B(i)<D_min
        E(i)=B(i)+D_min; 
    end
end