function string_to_esmf_timeinterval(time_interval_string,unusable,rc) result(time_interval)
character(len=*), intent(in) :: time_interval_string
class(KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc
type(ESMF_TimeInterval) :: time_interval
integer :: status
integer :: strlen,ppos,cpos,lpos,tpos
integer year,month,day,hour,min,sec
character(len=:), allocatable :: date_string,time_string
_UNUSED_DUMMY(unusable)
year=0
month=0
day=0
hour=0
min=0
sec=0
strlen = len_trim(time_interval_string)
tpos = index(time_interval_string,'T')
ppos = index(time_interval_string,'P')
_ASSERT(time_interval_string(1:1) == 'P','Not valid time duration')
if (tpos /= 0) then
if (tpos /= ppos+1) then
date_string = time_interval_string(ppos+1:tpos-1)
end if
time_string = time_interval_string(tpos+1:strlen)
else
date_string = time_interval_string(ppos+1:strlen)
end if
if (allocated(date_string)) then
strlen = len_trim(date_string)
lpos = 0
cpos = index(date_string,'Y')
if (cpos /= 0) then
read(date_string(lpos+1:cpos-1),*)year
lpos = cpos
end if
cpos = index(date_string,'M')
if (cpos /= 0) then
read(date_string(lpos+1:cpos-1),*)month
lpos = cpos
end if
cpos = index(date_string,'D')
if (cpos /= 0) then
read(date_string(lpos+1:cpos-1),*)day
lpos = cpos
end if
end if
if (allocated(time_string)) then
strlen = len_trim(time_string)
lpos = 0
cpos = index(time_string,'H')
if (cpos /= 0) then
read(time_string(lpos+1:cpos-1),*)hour
lpos = cpos
end if
cpos = index(time_string,'M')
if (cpos /= 0) then
read(time_string(lpos+1:cpos-1),*)min
lpos = cpos
end if
cpos = index(time_string,'S')
if (cpos /= 0) then
read(time_string(lpos+1:cpos-1),*)sec
lpos = cpos
end if
end if
call ESMF_TimeIntervalSet(time_interval,yy=year,mm=month,d=day,h=hour,m=min,s=sec,_RC)
_RETURN(_SUCCESS)
end function string_to_esmf_timeinterval