From 3ff34d309d98c389388e54d37d68524893283a56 Mon Sep 17 00:00:00 2001
From: jfe <git@jfengels.de>
Date: Tue, 18 Dec 2018 13:15:12 +0100
Subject: [PATCH] Add t_timedelta%toSeconds() / %toMilliSeconds()

---
 examples/example_hl.f90 |  4 ++++
 src/libmtime_hl.f90     | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/examples/example_hl.f90 b/examples/example_hl.f90
index 62d46f0e..5b7639c5 100644
--- a/examples/example_hl.f90
+++ b/examples/example_hl.f90
@@ -80,4 +80,8 @@ PROGRAM example
   ! produce error
   dt = t_datetime("1970--01-01T00:00:00")
 
+  ! toSeconds, toMilliSeconds
+  WRITE (0,*) td%to_string(), " is in seconds ", td%toSeconds(dt)
+  WRITE (0,*) td%to_string(), " is in milliseconds ", td%toMilliSeconds(dt)
+
 END PROGRAM example
diff --git a/src/libmtime_hl.f90 b/src/libmtime_hl.f90
index 6a0d466d..9f6c917a 100644
--- a/src/libmtime_hl.f90
+++ b/src/libmtime_hl.f90
@@ -85,6 +85,8 @@ module mtime_hl
     procedure :: assign_t_timedelta
 
     procedure :: t_timedelta_divideInSecondsBy
+    procedure :: t_timedelta_toSeconds
+    procedure :: t_timedelta_toMilliSeconds
 
     procedure :: equal_datetime            => t_timedelta_equal
     procedure :: not_equal_datetime        => t_timedelta_not_equal
@@ -100,6 +102,8 @@ module mtime_hl
     procedure :: t_timedelta_to_string
 
     generic   :: divideInSecondsBy => t_timedelta_divideInSecondsBy
+    generic   :: toSeconds => t_timedelta_toSeconds
+    generic   :: toMilliSeconds => t_timedelta_toMilliSeconds
 
     generic   :: to_string => t_timedelta_to_string
     
@@ -524,6 +528,22 @@ contains
      CALL divideTimeDeltaInSeconds(this%td, divisor%td, quotient)
   end function t_timedelta_divideInSecondsBy
 
+  function t_timedelta_toSeconds (this, td) result(seconds)
+     CLASS(t_timedelta), INTENT(in) :: this
+     TYPE(t_datetime),   INTENT(in) :: td
+     INTEGER(c_int64_t)             :: seconds
+
+     seconds = getTotalSecondsTimeDelta(this%td, td%dt)
+  end function t_timedelta_toSeconds
+
+  function t_timedelta_toMilliSeconds (this, td) result(ms)
+     CLASS(t_timedelta), INTENT(in) :: this
+     TYPE(t_datetime),   INTENT(in) :: td
+     INTEGER(c_int64_t)             :: ms
+
+     ms = getTotalMilliSecondsTimeDelta(this%td, td%dt)
+  end function t_timedelta_toMilliSeconds
+
   function t_datetime_min(a,b) result(res)
     type(t_datetime) :: a,b
     type(t_datetime) :: res
-- 
GitLab