<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def date2doy(time: Union[str, datetime.datetime]) -> Tuple[int, int]: """ < 366 for leap year too. normal year 0..364. Leap 0..365. """


    T = np.atleast_1d(time)

    year = np.empty(T.size, dtype=int)
    doy = np.empty_like(year)

    for i, t in enumerate(T):
        yd = str(datetime2yeardoy(t)[0])

        year[i] = int(yd[:4])
        doy[i] = int(yd[4:])

    assert ((0 < doy) & (doy < 366)).all(), 'day of year must be 0 < doy < 366'

    return doy, year