From ff7088fa2fbf13b26a970bca4e432da2e8bc8c3b Mon Sep 17 00:00:00 2001
From: jfe <git@jfengels.de>
Date: Tue, 18 Dec 2018 11:32:54 +0100
Subject: [PATCH] Rap divideInSecondsBy.

---
 examples/example_hl.f90 | 13 ++++++++++---
 src/libmtime_hl.f90     | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/examples/example_hl.f90 b/examples/example_hl.f90
index 6745a2de..3f347e3e 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 440a3cc9..95b2cd29 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
-- 
GitLab