From f720f80c390926a04ea7adecd5cfc9fe81518229 Mon Sep 17 00:00:00 2001 From: jfe <git@jfengels.de> Date: Tue, 18 Dec 2018 10:31:54 +0100 Subject: [PATCH] Add min and max to limtime_hl.f9000 --- examples/example_hl.f90 | 11 ++++++++--- src/libmtime_hl.f90 | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/examples/example_hl.f90 b/examples/example_hl.f90 index b335d55e..c0b46fd9 100644 --- a/examples/example_hl.f90 +++ b/examples/example_hl.f90 @@ -26,12 +26,11 @@ PROGRAM example USE mo_example USE mtime, ONLY: setCalendar, PROLEPTIC_GREGORIAN - USE mtime_hl, ONLY: t_datetime, t_timedelta - USE error_handling + USE mtime_hl, ONLY: t_datetime, t_timedelta, min, max IMPLICIT NONE - TYPE(t_datetime) :: dt, dt2, dt3 + TYPE(t_datetime) :: dt, dt2, dt3, dt4 TYPE(t_timedelta) :: td INTEGER :: test_number1, test_number2, test_result @@ -86,6 +85,12 @@ PROGRAM example dt3 = t_datetime("1970-01-01T00:00:01") WRITE (0,*) dt%to_string(), " == ", dt3%to_string(), ": ", (dt == dt3) + ! min / max + dt4 = min(dt2,dt3) + WRITE (0,*) "MIN(", dt2%to_string(), ", ", dt3%to_string(), "): ", dt4%to_string() + dt4 = max(dt2,dt3) + WRITE (0,*) "MAX(", dt2%to_string(), ", ", dt3%to_string(), "): ", dt4%to_string() + ! interval assignment with milliseconds td = t_timedelta(360000) WRITE (0,*) "interval assignment with milliseconds: ", td%to_string() diff --git a/src/libmtime_hl.f90 b/src/libmtime_hl.f90 index 30eae006..8199d97c 100644 --- a/src/libmtime_hl.f90 +++ b/src/libmtime_hl.f90 @@ -16,8 +16,13 @@ module mtime_hl private +<<<<<<< Updated upstream PUBLIC :: t_datetime, t_timedelta PUBLIC :: t_timedeltaFromMilliseconds +======= + public :: t_datetime, t_timedelta + public :: min, max +>>>>>>> Stashed changes integer, parameter :: i8 = selected_int_kind(14) !< at least 8 byte integer @@ -94,6 +99,14 @@ module mtime_hl END INTERFACE t_timedeltaFromMilliseconds + interface min + module procedure t_datetime_min + end interface min + + interface max + module procedure t_datetime_max + end interface max + contains !___________________________________________________________________________ @@ -324,6 +337,28 @@ contains call deallocatetimedelta(td_tmp) end function t_timedelta_to_string + function t_datetime_min(a,b) result(res) + type(t_datetime) :: a,b + type(t_datetime) :: res + + if (a > b) then + res = b + else + res = a + end if + end function t_datetime_min + + function t_datetime_max(a,b) result(res) + type(t_datetime) :: a,b + type(t_datetime) :: res + + if (a > b) then + res = a + else + res = b + end if + end function t_datetime_max + end module mtime_hl !> !! @} -- GitLab