subroutine parse_timeunit_i8(tunit, n, t0, dt, rc)
use ESMF
implicit none
character(len=*), intent(in) :: tunit
integer(ESMF_KIND_I8), intent(in) :: n
type(ESMF_Time), intent(out) :: t0
type(ESMF_TimeInterval), intent(out) :: dt
integer, optional, intent(out) :: rc
integer :: status
integer :: i
character(len=ESMF_MAXSTR) :: s1, s2, s_time, s_unit
character(len=1) :: c1
integer :: y,m,d,hour,min,sec
integer(ESMF_KIND_I8) :: isec
i=index(trim(tunit), 'since')
s_time=trim(tunit(i+5:))
s_unit=trim(tunit(1:i-1))
read(s_time,*) s1, s2
read(s1, '(i4,a1,i2,a1,i2)') y, c1, m, c1, d
read(s2, '(i2,a1,i2,a1,i2)') hour, c1, min, c1, sec
! write(6,*) 'y, c1, m, c1, d', y, c1, m, c1, d
! write(6,*) 'hour, c1, min, c1, sec', hour, c1, min, c1, sec
if (trim(s_unit) == 'seconds') then
isec=n
elseif (trim(s_unit) == 'minutes') then
isec=n * 60
elseif (trim(s_unit) == 'hours') then
isec=n * 3600
else
_FAIL ('time_unit not implemented')
end if
call ESMF_timeSet(t0, yy=y,mm=m,dd=d,h=hour,m=min,s=sec, _RC)
call ESMF_timeintervalSet(dt, d=0, h=0, m=0, s_i8=isec, _RC)
_RETURN(_SUCCESS)
end subroutine parse_timeunit_i8