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
d57684ab
Commit
d57684ab
authored
5 years ago
by
Florian Prill
Browse files
Options
Downloads
Patches
Plain Diff
[develop] allow for scalar timeDelta multiplication up to 29 days.
parent
60e8af19
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/example_hl.f90
+5
-0
5 additions, 0 deletions
examples/example_hl.f90
src/mtime_timedelta.c
+42
-20
42 additions, 20 deletions
src/mtime_timedelta.c
with
47 additions
and
20 deletions
examples/example_hl.f90
+
5
−
0
View file @
d57684ab
...
...
@@ -94,6 +94,11 @@ PROGRAM example
td
=
t_timedelta
(
"PT1H"
)
td
=
td
*
0.5_c_double
WRITE
(
0
,
*
)
" PT1H * 0.5 = "
,
td
%
toString
()
td
=
t_timedelta
(
"PT1H"
)
td
=
td
*
25
WRITE
(
0
,
*
)
" PT1H * 25 = "
,
td
%
toString
()
! Cray bug? Doesn't seem to recognize OPERATOR(*)
#ifndef _CRAYFTN
td
=
t_timedelta
(
"PT1H"
)
...
...
This diff is collapsed.
Click to expand it.
src/mtime_timedelta.c
+
42
−
20
View file @
d57684ab
...
...
@@ -1774,6 +1774,10 @@ moduloTimeDeltaFromDateTime(struct _datetime* start_dt, struct _timedelta* times
struct
_timedelta
*
elementwiseScalarMultiplyTimeDelta
(
struct
_timedelta
*
base_td
,
int64_t
lambda
,
struct
_timedelta
*
scaled_td
)
{
/* scalar multiplication is well-defined/implmented for
days<=MAX_DAYS_ALLOWED. */
const
int
MAX_DAYS_ALLOWED
=
29
;
if
((
base_td
!=
NULL
)
&&
(
scaled_td
!=
NULL
)
)
{
/* Scalar multiplication not supported for TimeDeltas consisting of day/month/year. */
...
...
@@ -1793,6 +1797,9 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
if
(
lambda
<
0
)
lambda
*=
-
1
;
scaled_td
->
day
=
0
;
scaled_td
->
month
=
0
;
scaled_td
->
year
=
0
;
/* Multiply each element by scalar. */
...
...
@@ -1818,17 +1825,18 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
}
scaled_td
->
hour
+=
(
int
)
lambda
*
base_td
->
hour
;
/* Scalar multiplication can not give a value in excess of 24 hours. */
if
(
scaled_td
->
hour
>=
NO_OF_HOURS_IN_A_DAY
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
scaled_td
->
day
=
0
;
scaled_td
->
month
=
0
;
scaled_td
->
year
=
0
;
while
(
scaled_td
->
hour
>=
NO_OF_HOURS_IN_A_DAY
)
{
scaled_td
->
hour
-=
NO_OF_HOURS_IN_A_DAY
;
scaled_td
->
day
+=
1
;
/* scalar multiplication is well-defined/implemented for
days<=MAX_DAYS_ALLOWED. */
if
(
scaled_td
->
day
>
MAX_DAYS_ALLOWED
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
}
return
scaled_td
;
...
...
@@ -1864,6 +1872,10 @@ elementwiseScalarMultiplyTimeDelta(struct _timedelta* base_td, int64_t lambda, s
struct
_timedelta
*
elementwiseScalarMultiplyTimeDeltaDP
(
struct
_timedelta
*
base_td
,
double
lambda
,
struct
_timedelta
*
scaled_td
)
{
/* scalar multiplication is well-defined/implmented for
days<=MAX_DAYS_ALLOWED. */
const
int
MAX_DAYS_ALLOWED
=
29
;
if
((
base_td
!=
NULL
)
&&
(
scaled_td
!=
NULL
)
)
{
/* Scalar multiplication not supported for TimeDeltas consisting of day/month/year. */
...
...
@@ -1880,24 +1892,34 @@ elementwiseScalarMultiplyTimeDeltaDP(struct _timedelta* base_td, double lambda,
if
(
lambda
<
0
.)
lambda
*=
-
1
.;
scaled_td
->
day
=
0
;
scaled_td
->
month
=
0
;
scaled_td
->
year
=
0
;
/* Multiply each element by scalar. */
scaled_td
->
hour
=
(
int
)
lambda
*
base_td
->
hour
;
/* Scalar multiplication can not give a value in excess of 24 hours. */
if
(
scaled_td
->
hour
>=
NO_OF_HOURS_IN_A_DAY
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
double
remainder_minutes
=
60
.
*
(
lambda
*
base_td
->
hour
-
scaled_td
->
hour
);
scaled_td
->
minute
=
(
int
)
(
lambda
*
base_td
->
minute
+
remainder_minutes
);
double
remainder_seconds
=
60
.
*
(
lambda
*
base_td
->
minute
+
remainder_minutes
-
scaled_td
->
minute
);
scaled_td
->
second
+=
(
int
)
(
lambda
*
base_td
->
second
+
remainder_seconds
);
double
remainder_ms
=
1000
.
*
((
lambda
*
base_td
->
second
+
remainder_seconds
)
-
scaled_td
->
second
);
scaled_td
->
ms
=
(
int
)
(
lambda
*
base_td
->
ms
+
remainder_ms
);
scaled_td
->
day
=
0
;
scaled_td
->
month
=
0
;
scaled_td
->
year
=
0
;
while
(
scaled_td
->
hour
>=
NO_OF_HOURS_IN_A_DAY
)
{
scaled_td
->
hour
-=
NO_OF_HOURS_IN_A_DAY
;
scaled_td
->
day
+=
1
;
/* scalar multiplication is well-defined/implemented for
days<=MAX_DAYS_ALLOWED. */
if
(
scaled_td
->
day
>
MAX_DAYS_ALLOWED
)
{
/* ERROR: Return on NULL. */
return
NULL
;
}
}
return
scaled_td
;
}
else
...
...
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