diff --git a/examples/example_hl.f90 b/examples/example_hl.f90 index 6745a2debc9a8a47f45d29d1315c3329a47ea9f2..3f347e3efbd5787b934ed024dfc6c5c758887316 100644 --- a/examples/example_hl.f90 +++ b/examples/example_hl.f90 @@ -3,12 +3,14 @@ PROGRAM example USE mtime, ONLY: setCalendar, PROLEPTIC_GREGORIAN USE mtime_hl, ONLY: t_datetime, t_timedelta, min, max, & - & t_timedeltaFromMilliseconds + & t_timedeltaFromMilliseconds, & + & divisionquotienttimespan IMPLICIT NONE TYPE(t_datetime) :: dt, dt2, dt3, dt4 - TYPE(t_timedelta) :: td + TYPE(t_timedelta) :: td, td1 + TYPE(divisionquotienttimespan) :: dqts INTEGER :: test_number1, test_number2, test_result @@ -69,5 +71,10 @@ PROGRAM example ! interval assignment with milliseconds td = t_timedeltaFromMilliseconds(360000) WRITE (0,*) "interval assignment with milliseconds: ", td%to_string() - + + ! division + td1 = t_timedelta("PT23H42M") + dqts = td1%divideInSecondsBy(td) + WRITE (0,*) td1%to_string(), " / ", td%to_string(), " = ", dqts%quotient, " plus stuff" + END PROGRAM example diff --git a/src/libmtime_hl.f90 b/src/libmtime_hl.f90 index 440a3cc91a1b14f3a2bf9c26961789ec23350189..95b2cd2927b33cf4b0d2a6386b4ab15b5d3a48e4 100644 --- a/src/libmtime_hl.f90 +++ b/src/libmtime_hl.f90 @@ -20,6 +20,9 @@ module mtime_hl PUBLIC :: t_timedeltaFromMilliseconds PUBLIC :: min, max + ! Re-export stuff from libmtime that is still needed + PUBLIC :: divisionquotienttimespan + integer, parameter :: i8 = selected_int_kind(14) !< at least 8 byte integer @@ -78,9 +81,12 @@ module mtime_hl contains procedure :: assign_t_timedelta + procedure :: t_timedelta_divideInSecondsBy procedure :: t_timedelta_to_string - + + generic :: divideInSecondsBy => t_timedelta_divideInSecondsBy + generic :: to_string => t_timedelta_to_string generic :: assignment(=) => assign_t_timedelta @@ -334,6 +340,14 @@ contains call deallocatetimedelta(td_tmp) end function t_timedelta_to_string + function t_timedelta_divideInSecondsBy (this, divisor) result(quotient) + CLASS(t_timedelta), INTENT(in) :: this + TYPE(t_timedelta), INTENT(in) :: divisor + TYPE(divisionquotienttimespan) :: quotient + + CALL divideTimeDeltaInSeconds(this%td, divisor%td, quotient) + end function t_timedelta_divideInSecondsBy + function t_datetime_min(a,b) result(res) type(t_datetime) :: a,b type(t_datetime) :: res