5 #define geth_newdate geth_newdate
7 #define geth_newdate geth_newdate_
11 int geti(char *s
, int p
, int l
);
13 void geth_newdate(char * date
, int * increment
, char * newdate
)
18 int yrold
, moold
, dyold
, hrold
, miold
, scold
, frold
, i
, j
;
19 int yrnew
, monew
, dynew
, hrnew
, minew
, scnew
, frnew
;
26 int nday
, nhour
, nmin
, nsec
, nfrac
;
27 char Continuous
, SwapFmt
;
58 /* We have the form YYYYMMDDHH */
61 yrold
= geti(hh
, 0, 4);
62 moold
= geti(hh
, 4, 2);
64 dyold
= geti(hh
, 6, 2);
67 hrold
= geti(hh
, 8, 2);
70 miold
= geti(hh
, 10,2);
73 scold
= geti(hh
, 12,2);
76 frold
= geti(hh
, 14,ilen
-13);
84 mday
[1] = nfeb(yrold
);
86 /* Compute the number of days, hours, minutes, and seconds in idt */
88 if (ilen
> 19) /*idt should be in fractions of seconds*/
90 if (ilen
== 20) ifrc
= 10;
91 if (ilen
== 21) ifrc
= 100;
92 if (ilen
== 22) ifrc
= 1000;
93 if (ilen
== 23) ifrc
= 10000;
94 nday
= abs(idt
)/(86400*ifrc
);
95 nhour
= div(abs(idt
), 86400*ifrc
).rem
/(3600*ifrc
);
96 nmin
= div(abs(idt
), 3600*ifrc
).rem
/(60*ifrc
);
97 nsec
= div(abs(idt
), 60*ifrc
).rem
/ifrc
;
98 nfrac
= div(abs(idt
), ifrc
).rem
;
100 else if (ilen
> 17) /* idt should be in seconds */
103 nday
= abs(idt
)/86400; /* Integer number of days in delta-time */
104 nhour
= div(abs(idt
), 86400).rem
/3600;
105 nmin
= div(abs(idt
), 3600).rem
/60;
106 nsec
= div(abs(idt
), 60).rem
;
109 else if (ilen
> 14) /*idt should be in minutes */
112 nday
= abs(idt
)/1440; /* Integer number of days in delta-time */
113 nhour
= div(abs(idt
), 1440).rem
/60;
114 nmin
= div(abs(idt
), 60).rem
;
118 else if (ilen
> 11) /* idt should be in hours */
121 nday
= abs(idt
)/24; /* Integer number of days in delta-time */
122 nhour
= div(abs(idt
),24).rem
;
127 else if (ilen
> 8) /* idt should be in days */
130 nday
= abs(idt
); /* Integer number of days in delta-time */
138 printf("Strangeness\n");
152 frnew
= frold
+ nfrac
;
154 frnew
= frnew
- ifrc
;
157 scnew
= scold
+ nsec
;
162 minew
= miold
+ nmin
;
167 hrnew
= hrold
+ nhour
;
175 for(i
= 1; i
<= nday
; i
++){
177 if (dynew
> mday
[monew
-1]) {
178 dynew
= dynew
- mday
[monew
-1];
183 /* If the year changes, recompute the number of days in February */
184 mday
[1] = nfeb(yrnew
); }
191 frnew
= frold
- nfrac
;
193 frnew
= frnew
+ ifrc
;
196 scnew
= scold
- nsec
;
201 minew
= miold
- nmin
;
206 hrnew
= hrold
- nhour
;
214 for(i
= 1; i
<= nday
; i
++){
221 /* If the year changes, recompute the number of days in February */
222 mday
[1] = nfeb(yrnew
);
224 dynew
= mday
[monew
-1];
229 sprintf(newdate
, "%4.4i%2.2i%2.2i%2.2i",yrnew
, monew
, dynew
, hrnew
);
237 nfeb
= 28; /* By default, February has 28 days ... */
238 if (div(year
,4).rem
== 0){
239 nfeb
= 29; /* But every four years, it has 29 days ... */
240 if (div(year
,100).rem
== 0) {
241 nfeb
= 28; /* Except every 100 years, when it has 28 days ... */
242 if (div(year
,400).rem
== 0){
243 nfeb
= 29; /* Except every 400 years, when it has 29 days ... */
244 if (div(year
,3600).rem
== 0){
245 nfeb
= 28; /* Except every 3600 years, when it has 28 days. */
253 int geti(char *s
, int p
, int l
)
257 for (i
=0; i
<l
; i
++) {
258 ival
= (ival
*10) + s
[p
+i
]-'0';