diff --git a/examples/example_hl.f90 b/examples/example_hl.f90 index 62d46f0e2579d617fd8199c5072bb0900e668915..5b7639c5e3463ebb7a86ff7d97a5ae721853f033 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 6a0d466d26d9ea35d9a470ce7d41cebd3fd65c53..9f6c917abacfd7c494628dd2017c5acd2104cb40 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