8 #include <grass/datetime.h>
43 static int _datetime_ymd_to_ddays(
const DateTime *,
double *);
44 static int _datetime_compare(
const DateTime *,
const DateTime *);
80 DateTime tb, ta, *early, *late;
98 "only one opperand contains valid timezone");
103 ta.to < DATETIME_DAY ? DATETIME_YEAR : DATETIME_DAY,
105 compare = _datetime_compare(&ta, &tb);
109 result->positive = 1;
111 else if (compare < 0) {
114 result->positive = 0;
124 if (ta.positive == tb.positive) {
126 result->year = abs(late->year - early->year);
129 result->year = late->year + early->year - 2;
131 dm = late->month - early->month;
136 result->month = dm + 12;
141 double latedays, earlydays;
144 _datetime_ymd_to_ddays(early, &earlydays);
146 erel.day = earlydays;
147 erel.hour = early->hour;
148 erel.minute = early->minute;
149 erel.second = early->second;
152 _datetime_ymd_to_ddays(late, &latedays);
155 lrel.hour = late->hour;
156 lrel.minute = late->minute;
157 lrel.second = late->second;
163 result->day = erel.day;
164 result->hour = erel.hour;
165 result->minute = erel.minute;
166 result->second = erel.second;
181 static int _datetime_compare(
const DateTime *a,
const DateTime *
b)
185 if (a->positive && !
b->positive)
187 else if (
b->positive && !a->positive)
191 for (i = a->from; i <= a->to; i++) {
194 case DATETIME_SECOND:
195 if (a->second >
b->second)
197 else if (a->second <
b->second)
201 case DATETIME_MINUTE:
202 if (a->minute >
b->minute)
204 else if (a->minute <
b->minute)
209 if (a->hour >
b->hour)
211 else if (a->hour <
b->hour)
218 else if (a->day <
b->day)
223 if (a->month >
b->month)
225 else if (a->month <
b->month)
231 if (a->year >
b->year)
233 else if (a->year <
b->year)
237 if (a->year <
b->year)
239 else if (a->year >
b->year)
250 static int _datetime_ymd_to_ddays(
const DateTime *dtymd,
double *days)
256 if (dtymd->positive) {
257 *days = dtymd->day - 1;
258 for (mo = dtymd->month - 1; mo > 0; mo--) {
261 for (yr = dtymd->year - 1; yr > 0; yr--) {
266 for (yr = dtymd->year - 1; yr > 0; yr--) {
269 for (mo = 12; mo >= dtymd->month;
int datetime_change_from_to(DateTime *dt, int from, int to, int round)
Changes the from/to of the type for dt. The 'from/to' must be legal values for the mode of dt; (if th...
void datetime_copy(DateTime *dst, const DateTime *src)
Copies the DateTime [into/from ???] src.
int datetime_error(int code, char *msg)
record 'code' and 'msg' as error code/msg (in static variables) code==0 will clear the error (ie set ...
int datetime_difference(const DateTime *a, const DateTime *b, DateTime *result)
This performs the formula: result = a - b;.
int datetime_increment(DateTime *src, DateTime *incr)
This function changes the 'src' date/time data based on the 'incr' The type (mode/from/to) of the 'sr...
int datetime_set_increment_type(const DateTime *src, DateTime *incr)
src must be legal This is a convenience routine which is implemented as follows:
int datetime_days_in_month(int year, int month, int ad)
returns number of days in 'month' of a particular 'year'
int datetime_days_in_year(int year, int ad)
returns the number of days in 'year'
void datetime_invert_sign(DateTime *dt)
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
int datetime_in_interval_year_month(int x)
int datetime_get_timezone(const DateTime *dt, int *minutes)
returns 0 on success
int datetime_change_to_utc(DateTime *dt)
Return datetime_change_timezone (dt, 0);.