Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
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
mpim-sw
libcdi
Commits
beb49d96
Commit
beb49d96
authored
9 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
Merge declaration and definition.
parent
6e1df024
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/calendar.c
+31
-47
31 additions, 47 deletions
src/calendar.c
with
31 additions
and
47 deletions
src/calendar.c
+
31
−
47
View file @
beb49d96
...
...
@@ -14,35 +14,33 @@ static int month_366[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int
calendar_dpy
(
int
calendar
)
{
int
d
py
=
0
;
int
d
aysperyear
=
0
;
if
(
calendar
==
CALENDAR_360DAYS
)
d
py
=
360
;
else
if
(
calendar
==
CALENDAR_365DAYS
)
d
py
=
365
;
else
if
(
calendar
==
CALENDAR_366DAYS
)
d
py
=
366
;
if
(
calendar
==
CALENDAR_360DAYS
)
d
aysperyear
=
360
;
else
if
(
calendar
==
CALENDAR_365DAYS
)
d
aysperyear
=
365
;
else
if
(
calendar
==
CALENDAR_366DAYS
)
d
aysperyear
=
366
;
return
(
dpy
)
;
return
daysperyear
;
}
int
days_per_month
(
int
calendar
,
int
year
,
int
month
)
{
int
dayspermonth
=
0
;
int
*
dpm
=
NULL
;
int
dpy
;
dpy
=
calendar_dpy
(
calendar
);
int
daysperyear
=
calendar_dpy
(
calendar
);
if
(
d
py
==
360
)
dpm
=
month_360
;
else
if
(
d
py
==
365
)
dpm
=
month_365
;
else
dpm
=
month_366
;
if
(
d
aysperyear
==
360
)
dpm
=
month_360
;
else
if
(
d
aysperyear
==
365
)
dpm
=
month_365
;
else
dpm
=
month_366
;
int
dayspermonth
=
0
;
if
(
month
>=
1
&&
month
<=
12
)
dayspermonth
=
dpm
[
month
-
1
];
/*
else
fprintf(stderr, "days_per_month: month %d out of range\n", month);
*/
if
(
d
py
==
0
&&
month
==
2
)
if
(
d
aysperyear
==
0
&&
month
==
2
)
{
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
dayspermonth
=
29
;
...
...
@@ -50,40 +48,35 @@ int days_per_month(int calendar, int year, int month)
dayspermonth
=
28
;
}
return
(
dayspermonth
)
;
return
dayspermonth
;
}
int
days_per_year
(
int
calendar
,
int
year
)
{
int
daysperyear
;
int
dpy
;
dpy
=
calendar_dpy
(
calendar
);
int
daysperyear
=
calendar_dpy
(
calendar
);
if
(
d
py
==
0
)
if
(
d
aysperyear
==
0
)
{
if
(
calendar
==
CALENDAR_STANDARD
)
{
if
(
year
==
1582
)
d
py
=
355
;
d
aysperyear
=
355
;
else
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
d
py
=
366
;
d
aysperyear
=
366
;
else
d
py
=
365
;
d
aysperyear
=
365
;
}
else
{
if
(
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
)
d
py
=
366
;
d
aysperyear
=
366
;
else
d
py
=
365
;
d
aysperyear
=
365
;
}
}
daysperyear
=
dpy
;
return
(
daysperyear
);
return
daysperyear
;
}
...
...
@@ -122,7 +115,7 @@ static int encode_day(int dpy, int year, int month, int day)
else
if
(
dpy
==
366
)
dpm
=
month_366
;
if
(
dpm
)
for
(
i
=
0
;
i
<
month
-
1
;
i
++
)
rval
+=
dpm
[
i
];
if
(
rval
>
INT_MAX
||
rval
<
INT_MIN
)
if
(
rval
>
INT_MAX
||
rval
<
INT_MIN
)
Error
(
"Unhandled date: %ld"
,
rval
);
return
(
int
)
rval
;
...
...
@@ -132,9 +125,7 @@ static int encode_day(int dpy, int year, int month, int day)
void
encode_caldaysec
(
int
calendar
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
*
julday
,
int
*
secofday
)
{
int
dpy
;
dpy
=
calendar_dpy
(
calendar
);
int
dpy
=
calendar_dpy
(
calendar
);
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
*
julday
=
encode_day
(
dpy
,
year
,
month
,
day
);
...
...
@@ -145,12 +136,10 @@ void encode_caldaysec(int calendar, int year, int month, int day, int hour, int
}
void
decode_caldaysec
(
int
calendar
,
int
julday
,
int
secofday
,
void
decode_caldaysec
(
int
calendar
,
int
julday
,
int
secofday
,
int
*
year
,
int
*
month
,
int
*
day
,
int
*
hour
,
int
*
minute
,
int
*
second
)
{
int
dpy
;
dpy
=
calendar_dpy
(
calendar
);
int
dpy
=
calendar_dpy
(
calendar
);
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
decode_day
(
dpy
,
julday
,
year
,
month
,
day
);
...
...
@@ -166,39 +155,34 @@ void decode_caldaysec(int calendar, int julday, int secofday,
#ifdef TEST
static
int
date_to_calday
(
int
calendar
,
int
date
)
{
int
calday
;
int
dpy
;
int
year
,
month
,
day
;
dpy
=
calendar_dpy
(
calendar
);
int
dpy
=
calendar_dpy
(
calendar
);
int
year
,
month
,
day
;
cdiDecodeDate
(
date
,
&
year
,
&
month
,
&
day
);
int
calday
;
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
calday
=
encode_day
(
dpy
,
year
,
month
,
day
);
else
calday
=
encode_julday
(
calendar
,
year
,
month
,
day
);
return
(
calday
)
;
return
calday
;
}
static
int
calday_to_date
(
int
calendar
,
int
calday
)
{
int
date
;
int
dpy
;
int
year
,
month
,
day
;
dpy
=
calendar_dpy
(
calendar
);
int
dpy
=
calendar_dpy
(
calendar
);
if
(
dpy
==
360
||
dpy
==
365
||
dpy
==
366
)
decode_day
(
dpy
,
calday
,
&
year
,
&
month
,
&
day
);
else
decode_julday
(
calendar
,
calday
,
&
year
,
&
month
,
&
day
);
date
=
cdiEncodeDate
(
year
,
month
,
day
);
int
date
=
cdiEncodeDate
(
year
,
month
,
day
);
return
(
date
)
;
return
date
;
}
...
...
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