Skip to content
Snippets Groups Projects
Commit f720f80c authored by Jan Frederik Engels's avatar Jan Frederik Engels :new_moon:
Browse files

Add min and max to limtime_hl.f9000

parent c85ff756
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -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
!>
!! @}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment