Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
YAC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
dkrz-sw
YAC
Commits
90ff2903
Commit
90ff2903
authored
6 years ago
by
Rene Redler
Browse files
Options
Downloads
Patches
Plain Diff
updates to libmtime 1.0.8
parent
6134c295
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
mtime/include/mtime_datetime.h
+7
-2
7 additions, 2 deletions
mtime/include/mtime_datetime.h
mtime/src/mtime_datetime.c
+0
-20
0 additions, 20 deletions
mtime/src/mtime_datetime.c
mtime/src/mtime_timedelta.c
+69
-77
69 additions, 77 deletions
mtime/src/mtime_timedelta.c
with
76 additions
and
99 deletions
mtime/include/mtime_datetime.h
+
7
−
2
View file @
90ff2903
...
...
@@ -71,8 +71,13 @@ int
getNoOfDaysInYearDateTime
(
struct
_datetime
*
dt
);
/*! \cond PRIVATE */
bool
testYearIsLeapYear
(
int64_t
year
);
static
inline
bool
testYearIsLeapYear
(
int64_t
year
)
{
bool
isLeapYear
=
!
(
year
%
400
)
||
((
year
%
100
)
&&
!
(
year
%
4
));
return
isLeapYear
;
}
struct
_datetime
*
convertDateToDateTime
(
struct
_date
*
d
,
struct
_datetime
*
dt_return
);
...
...
This diff is collapsed.
Click to expand it.
mtime/src/mtime_datetime.c
+
0
−
20
View file @
90ff2903
...
...
@@ -336,26 +336,6 @@ else
}
/*! \cond PRIVATE */
/* Internal function. Test is year a leap year? */
bool
testYearIsLeapYear
(
int64_t
year
)
{
bool
flag
=
false
;
if
(
!
(
year
%
400
))
flag
=
true
;
else
if
(
!
(
year
%
100
))
flag
=
false
;
else
if
(
!
(
year
%
4
))
flag
=
true
;
else
flag
=
false
;
return
flag
;
}
/*
* NOTE: Internal and not doxyfied.
*
...
...
This diff is collapsed.
Click to expand it.
mtime/src/mtime_timedelta.c
+
69
−
77
View file @
90ff2903
...
...
@@ -868,21 +868,21 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
/* Set parameter according to calender. */
switch
(
getCalendarType
())
{
case
YEAR_OF_365_DAYS
:
case
YEAR_OF_365_DAYS
:
msdinm
=
monthSpecificDeltaInMonths365
;
ndiny
=
NO_OF_DAYS_IN_A_YEAR_FOR_CAL_TYPE365
;
break
;
case
YEAR_OF_360_DAYS
:
case
YEAR_OF_360_DAYS
:
msdinm
=
monthSpecificDeltaInMonths360
;
ndiny
=
NO_OF_DAYS_IN_A_YEAR_FOR_CAL_TYPE360
;
break
;
case
PROLEPTIC_GREGORIAN
:
case
PROLEPTIC_GREGORIAN
:
/* Handle all Gregorian related code here. */
/* Gregorian will have 366 days and 365 days depending on Leap year. */
if
(
jd
->
sign
==
'-'
)
...
...
@@ -895,42 +895,42 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
/* No of days in the final year */
int64_t
delta_final_year
;
int64_t
days
=
(
-
1
)
*
jd
->
day
;
/* Set counter to base year and then
jump for
ward to get to the final year.
For each loop forward, increment year by 1.
*/
/* Set counter to base year and then
iterate back
ward to get to the final year.
For each loop forward, increment year by 1.
*/
int64_t
j
=
base_dt
->
date
.
year
;
/* Initialize to 0. */
td_return
->
year
=
0
;
/* Fast-Fwd >= 400 */
if
(
days
>=
NO_OF_DAYS_IN_400_YEARS
)
{
int64_t
numberOf400YearPeriods
=
days
/
NO_OF_DAYS_IN_400_YEARS
;
td_return
->
year
=
td_return
->
year
+
numberOf400YearPeriods
*
400
;
j
=
j
+
numberOf400YearPeriods
*
400
;
days
=
days
-
numberOf400YearPeriods
*
NO_OF_DAYS_IN_400_YEARS
;
}
{
int64_t
numberOf400YearPeriods
=
days
/
NO_OF_DAYS_IN_400_YEARS
;
td_return
->
year
=
td_return
->
year
+
numberOf400YearPeriods
*
400
;
j
=
j
-
numberOf400YearPeriods
*
400
;
days
=
days
-
numberOf400YearPeriods
*
NO_OF_DAYS_IN_400_YEARS
;
}
do
{
/* Loop over and get to the final year by substracting 366/365 days depending
on leap/non-leap year. For each substraction, increment year by 1.
*/
on leap/non-leap year. For each substraction, increment year by 1.
*/
/* The crucial point is month of february. */
delta_final_year
=
days
;
if
(
(
(
testYearIsLeapYear
(
j
+
1
))
&&
(
base_dt
->
date
.
month
>=
3
)
)
||
(
(
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
<
3
)
)
)
(
(
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
>=
3
)
)
||
(
(
testYearIsLeapYear
(
j
-
1
))
&&
(
base_dt
->
date
.
month
<
3
)
)
)
{
/* If
next
year is leap year and base month is >= 3
OR
this
year is a leap year and month is < 3
=> delta of 1 year corresponds to 366 day julian delta.
*/
/* If year is leap year and base month is >= 3
OR
next
year is a leap year and month is < 3
=> delta of 1 year corresponds to 366 day julian delta.
*/
days
=
days
-
NO_OF_DAYS_IN_A_LEAP_YEAR
;
}
else
...
...
@@ -939,27 +939,30 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
days
=
days
-
NO_OF_DAYS_IN_A_YEAR_FOR_CAL_TYPE365
;
}
td_return
->
year
++
;
j
++
;
}
while
(
days
>=
0
);
j
--
;
}
while
(
days
>=
0
);
/* The loop ran one time too much. */
if
(
days
<
0
)
{
td_return
->
year
--
;
j
--
;
j
++
;
}
/* In final year, the crucial point is the month of february. */
if
(
((
testYearIsLeapYear
(
j
+
1
))
&&
(
base_dt
->
date
.
month
>=
3
))
||
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
<
3
))
)
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
>=
3
))
||
((
testYearIsLeapYear
(
j
-
1
))
&&
(
base_dt
->
date
.
month
<
3
))
)
{
/* If final
year's next
year is a leap year and base month is >= 3
OR
final year is a leap year and month is < 3
=> An addition of leap-year specific delta for each month.
*/
/* If final year is a leap year and base month is >= 3
OR
year preceding
final year is a leap year and month is < 3
=> An addition of leap-year specific delta for each month.
*/
msdinm
=
monthSpecificDeltaInMonthsLeapyear
;
ndiny
=
NO_OF_DAYS_IN_A_LEAP_YEAR
;
}
...
...
@@ -996,39 +999,39 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
int64_t
delta_final_year
;
int64_t
days
=
jd
->
day
;
/* Set counter to base year and then loop back to get to the final year.
For each loop back, increment year by 1.
For each loop back, increment year by 1.
*/
int64_t
j
=
base_dt
->
date
.
year
;
/* Initialize. */
td_return
->
year
=
0
;
/* Fast-Fwd >= 400 */
if
(
days
>=
NO_OF_DAYS_IN_400_YEARS
)
{
int64_t
numberOf400YearPeriods
=
days
/
NO_OF_DAYS_IN_400_YEARS
;
td_return
->
year
=
td_return
->
year
+
numberOf400YearPeriods
*
400
;
j
=
j
-
numberOf400YearPeriods
*
400
;
days
=
days
-
numberOf400YearPeriods
*
NO_OF_DAYS_IN_400_YEARS
;
}
if
(
days
>=
NO_OF_DAYS_IN_400_YEARS
)
{
int64_t
numberOf400YearPeriods
=
days
/
NO_OF_DAYS_IN_400_YEARS
;
td_return
->
year
=
td_return
->
year
+
numberOf400YearPeriods
*
400
;
j
=
j
-
numberOf400YearPeriods
*
400
;
days
=
days
-
numberOf400YearPeriods
*
NO_OF_DAYS_IN_400_YEARS
;
}
do
{
/* Loop over and get the year by substracting 366/365 days depending
on leap/non-leap year. For each substraction, increment year by 1.
on leap/non-leap year. For each substraction, increment year by 1.
*/
/* The crucial point is month of february. */
delta_final_year
=
days
;
if
(
((
testYearIsLeapYear
(
j
-
1
))
&&
(
base_dt
->
date
.
month
<
3
))
||
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
>=
3
))
)
((
testYearIsLeapYear
(
j
+
1
))
&&
(
base_dt
->
date
.
month
>=
3
))
||
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
<
3
))
)
{
/* If
previous
year is leap year and base month is < 3
OR
this year is a leap year and month is
>=
3
=> delta of 1 year corresponds to 366 day julian delta.
/* If
next
year is leap year and base month is < 3
OR
this year is a leap year and month is
<
3
=> delta of 1 year corresponds to 366 day julian delta.
*/
days
=
days
-
NO_OF_DAYS_IN_A_LEAP_YEAR
;
}
...
...
@@ -1039,26 +1042,27 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
}
td_return
->
year
++
;
j
--
;
}
while
(
days
>=
0
);
j
++
;
}
while
(
days
>=
0
);
/* The loop ran one time too much. */
if
(
days
<
0
)
{
td_return
->
year
--
;
j
++
;
j
--
;
}
/* In final year, the crucial point is the month of february. */
if
(
((
testYearIsLeapYear
(
j
-
1
))
&&
(
base_dt
->
date
.
month
<
3
))
||
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
>=
3
))
)
((
testYearIsLeapYear
(
j
+
1
))
&&
(
base_dt
->
date
.
month
>=
3
))
||
((
testYearIsLeapYear
(
j
))
&&
(
base_dt
->
date
.
month
<
3
))
)
{
/* If final year is a leap year and base month is >= 3
OR
final year's previous year is a leap year and month is < 3
=> An addition of leap-year specific delta for each month.
/* If final year is a leap year and base month is >= 3
OR
final year's previous year is a leap year and month is < 3
=> An addition of leap-year specific delta for each month.
*/
msdinm
=
monthSpecificDeltaInMonthsLeapyear
;
ndiny
=
NO_OF_DAYS_IN_A_LEAP_YEAR
;
...
...
@@ -1070,18 +1074,6 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
ndiny
=
NO_OF_DAYS_IN_A_YEAR_FOR_CAL_TYPE365
;
}
/* for (i = NO_OF_MONTHS_IN_A_YEAR; i > 0; i--) */
/* { */
/* if (delta_final_year < (ndiny - msdinm[base_dt->date.month - 1][i - 1])) */
/* { */
/* // Month */
/* td_return->month = NO_OF_MONTHS_IN_A_YEAR - i; */
/* // Day */
/* td_return->day = (int) delta_final_year - (ndiny - msdinm[base_dt->date.month - 1][i]); */
/* break; */
/* } */
/* } */
td_return
->
month
=
0
;
td_return
->
day
=
(
int
)
delta_final_year
;
for
(
i
=
NO_OF_MONTHS_IN_A_YEAR
;
i
>
0
;
i
--
)
...
...
@@ -1093,7 +1085,7 @@ julianDeltaToTimeDelta(struct _juliandelta* jd, struct _datetime* base_dt, struc
break
;
}
}
/* Time */
td_return
->
hour
=
(
int
)
jd
->
ms
/
NO_OF_MS_IN_A_HOUR
;
td_return
->
minute
=
((
int
)
jd
->
ms
-
td_return
->
hour
*
NO_OF_MS_IN_A_HOUR
)
/
NO_OF_MS_IN_A_MINUTE
;
...
...
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