Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libmtime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
icon-libraries
libmtime
Commits
fbde4624
Commit
fbde4624
authored
8 years ago
by
Michael Weimer
Browse files
Options
Downloads
Patches
Plain Diff
[divideTwoDatetimeDiffs] added subroutine divideTwoDatetimeDifferencesInSeconds to mtime
parent
d700d766
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/mtime_timedelta.h
+3
-0
3 additions, 0 deletions
include/mtime_timedelta.h
src/libmtime.f90
+32
-0
32 additions, 0 deletions
src/libmtime.f90
src/mtime_timedelta.c
+58
-0
58 additions, 0 deletions
src/mtime_timedelta.c
with
93 additions
and
0 deletions
include/mtime_timedelta.h
+
3
−
0
View file @
fbde4624
...
...
@@ -90,6 +90,9 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime *dt, struct _ti
struct
_divisionquotienttimespan
*
divideTimeDeltaInSeconds
(
struct
_timedelta
*
dividend
,
struct
_timedelta
*
divisor
,
struct
_divisionquotienttimespan
*
quo_ret
);
struct
_divisionquotienttimespan
*
divideTwoDatetimeDifferencesInSeconds
(
struct
_datetime
*
dt1_dividend
,
struct
_datetime
*
dt2_dividend
,
struct
_datetime
*
dt1_divisor
,
struct
_datetime
*
dt2_divisor
,
struct
_divisionquotienttimespan
*
quo_ret
);
struct
_divisionquotienttimespan
*
divideDatetimeDifferenceInSeconds
(
struct
_datetime
*
dt1
,
struct
_datetime
*
dt2
,
struct
_timedelta
*
divisor
,
struct
_divisionquotienttimespan
*
quo_ret
);
...
...
This diff is collapsed.
Click to expand it.
src/libmtime.f90
+
32
−
0
View file @
fbde4624
...
...
@@ -1337,6 +1337,7 @@ module mtime_timedelta
public
::
getPTStringFromMinutes
public
::
getPTStringFromHours
public
::
divideTimeDeltaInSeconds
public
::
divideTwoDatetimeDifferencesInSeconds
public
::
divideDatetimeDifferenceInSeconds
public
::
operator
(
+
)
public
::
operator
(
-
)
...
...
@@ -1591,6 +1592,17 @@ module mtime_timedelta
type
(
c_ptr
),
value
::
quotient
end
function
my_divideTimeDeltaInSeconds
!
function
my_divideTwoDatetimeDifferencesInSeconds
(
dt1_dividend
,
dt2_dividend
,
dt1_divisor
,
dt2_divisor
,
quotient
)
result
(
ret_quotient
)
&
&
bind
(
c
,
name
=
'divideTwoDatetimeDifferencesInSeconds'
)
import
::
c_ptr
type
(
c_ptr
)
::
ret_quotient
type
(
c_ptr
),
value
::
dt1_dividend
type
(
c_ptr
),
value
::
dt2_dividend
type
(
c_ptr
),
value
::
dt1_divisor
type
(
c_ptr
),
value
::
dt2_divisor
type
(
c_ptr
),
value
::
quotient
end
function
my_divideTwoDatetimeDifferencesInSeconds
!
function
my_divideDatetimeDifferenceInSeconds
(
dt1
,
dt2
,
divisor
,
quotient
)
result
(
ret_quotient
)
&
&
bind
(
c
,
name
=
'divideDatetimeDifferenceInSeconds'
)
import
::
c_ptr
...
...
@@ -2170,6 +2182,26 @@ contains
type
(
c_ptr
)
::
dummy_ptr
dummy_ptr
=
my_dividetimedeltainseconds
(
c_loc
(
dividend
),
c_loc
(
divisor
),
c_loc
(
quotient
))
end
subroutine
divideTimeDeltaInSeconds
!>
!! @brief division of two differences in datetimes.
!!
!! @param dt1_dividend, dt2_dividend, dt1_divisor, dt2_divisor
!! Reference date (a pointer to struct _datetime).
!!
!! @param intvlsec
!! Interval given in seconds.
!!
!! @return result of division. NULL indicates error.
subroutine
divideTwoDatetimeDifferencesInSeconds
(
dt1_dividend
,
dt2_dividend
,
dt1_divisor
,
dt2_divisor
,
quotient
)
type
(
datetime
),
target
,
intent
(
in
)
::
dt1_dividend
type
(
datetime
),
target
,
intent
(
in
)
::
dt2_dividend
type
(
datetime
),
target
,
intent
(
in
)
::
dt1_divisor
type
(
datetime
),
target
,
intent
(
in
)
::
dt2_divisor
type
(
divisionquotienttimespan
),
target
,
intent
(
out
)
::
quotient
type
(
c_ptr
)
::
dummy_ptr
dummy_ptr
=
my_dividetwoDatetimedifferencesinseconds
(
c_loc
(
dt1_dividend
),
c_loc
(
dt2_dividend
),
c_loc
(
dt1_divisor
),
c_loc
(
dt2_divisor
),
c_loc
(
quotient
))
end
subroutine
divideTwoDatetimeDifferencesInSeconds
!>
!! @brief division of an datetime interval by seconds.
!!
...
...
This diff is collapsed.
Click to expand it.
src/mtime_timedelta.c
+
58
−
0
View file @
fbde4624
...
...
@@ -1255,6 +1255,64 @@ divideDatetimeDifferenceInSeconds(struct _datetime* dt1, struct _datetime* dt2,
return
NULL
;
}
/**
* @brief division of two differences in datetimes.
*
* @param dt1_dividend, dt2_dividend, dt1_divisor, dt2_divisor
* Reference date (a pointer to struct _datetime).
*
* @param intvlsec
* Interval given in seconds.
*
* @return result of division. NULL indicates error.
*/
struct
_divisionquotienttimespan
*
divideTwoDatetimeDifferencesInSeconds
(
struct
_datetime
*
dt1_dividend
,
struct
_datetime
*
dt2_dividend
,
struct
_datetime
*
dt1_divisor
,
struct
_datetime
*
dt2_divisor
,
struct
_divisionquotienttimespan
*
quo_ret
)
{
if
((
dt1_dividend
!=
NULL
)
&&
(
dt2_dividend
!=
NULL
)
&&
(
dt1_divisor
!=
NULL
)
&&
(
dt2_divisor
!=
NULL
)
&&
(
quo_ret
!=
NULL
))
{
// dividend
struct
_julianday
*
jd1_dividend
=
newJulianDay
(
0
,
0
);
if
(
jd1_dividend
!=
NULL
)
jd1_dividend
=
date2julian
(
dt1_dividend
,
jd1_dividend
);
struct
_julianday
*
jd2_dividend
=
newJulianDay
(
0
,
0
);
if
(
jd2_dividend
!=
NULL
)
jd2_dividend
=
date2julian
(
dt2_dividend
,
jd2_dividend
);
struct
_juliandelta
*
jd_dividend
=
newJulianDelta
(
'+'
,
0
,
0
);
jd_dividend
=
substractJulianDay
(
jd1_dividend
,
jd2_dividend
,
jd_dividend
);
intmax_t
numerator
=
(
intmax_t
)
(
jd_dividend
->
day
*
86400000
+
jd_dividend
->
ms
);
// divisor
struct
_julianday
*
jd1_divisor
=
newJulianDay
(
0
,
0
);
if
(
jd1_divisor
!=
NULL
)
jd1_divisor
=
date2julian
(
dt1_divisor
,
jd1_divisor
);
struct
_julianday
*
jd2_divisor
=
newJulianDay
(
0
,
0
);
if
(
jd2_divisor
!=
NULL
)
jd2_divisor
=
date2julian
(
dt2_divisor
,
jd2_divisor
);
struct
_juliandelta
*
jd_divisor
=
newJulianDelta
(
'+'
,
0
,
0
);
jd_divisor
=
substractJulianDay
(
jd1_divisor
,
jd2_divisor
,
jd_divisor
);
intmax_t
denominator
=
(
intmax_t
)
(
jd_divisor
->
day
*
86400000
+
jd_divisor
->
ms
);
imaxdiv_t
div
=
imaxdiv
(
numerator
,
denominator
);
quo_ret
->
quotient
=
(
int64_t
)
div
.
quot
;
quo_ret
->
remainder_in_ms
=
(
int64_t
)
div
.
rem
;
if
(
jd1_dividend
!=
NULL
)
deallocateJulianDay
(
jd1_dividend
);
if
(
jd2_dividend
!=
NULL
)
deallocateJulianDay
(
jd2_dividend
);
if
(
jd_dividend
!=
NULL
)
deallocateJulianDelta
(
jd_dividend
);
if
(
jd1_divisor
!=
NULL
)
deallocateJulianDay
(
jd1_divisor
);
if
(
jd2_divisor
!=
NULL
)
deallocateJulianDay
(
jd2_divisor
);
if
(
jd_divisor
!=
NULL
)
deallocateJulianDelta
(
jd_divisor
);
return
quo_ret
;
}
else
return
NULL
;
}
/**
* @brief Get the TimeDelta between two Dates d1 and d2 as (d1-d2).
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment