8#include <grass/datetime.h>
43static int _datetime_ymd_to_ddays(
const DateTime *,
double *);
44static int _datetime_compare(
const DateTime *,
const DateTime *);
81 DateTime tb, ta, *early, *late;
99 "only one opperand contains valid timezone");
104 ta.to < DATETIME_DAY ? DATETIME_YEAR : DATETIME_DAY,
106 compare = _datetime_compare(&ta, &tb);
110 result->positive = 1;
112 else if (compare < 0) {
115 result->positive = 0;
125 if (ta.positive == tb.positive) {
127 result->year = abs(late->year - early->year);
130 result->year = late->year + early->year - 2;
132 dm = late->month - early->month;
137 result->month = dm + 12;
142 double latedays, earlydays;
145 _datetime_ymd_to_ddays(early, &earlydays);
147 erel.day = earlydays;
148 erel.hour = early->hour;
149 erel.minute = early->minute;
150 erel.second = early->second;
153 _datetime_ymd_to_ddays(late, &latedays);
156 lrel.hour = late->hour;
157 lrel.minute = late->minute;
158 lrel.second = late->second;
164 result->day = erel.day;
165 result->hour = erel.hour;
166 result->minute = erel.minute;
167 result->second = erel.second;
182static int _datetime_compare(
const DateTime *a,
const DateTime *
b)
186 if (a->positive && !
b->positive)
188 else if (
b->positive && !a->positive)
192 for (i = a->from; i <= a->to; i++) {
195 case DATETIME_SECOND:
196 if (a->second >
b->second)
198 else if (a->second <
b->second)
202 case DATETIME_MINUTE:
203 if (a->minute >
b->minute)
205 else if (a->minute <
b->minute)
210 if (a->hour >
b->hour)
212 else if (a->hour <
b->hour)
219 else if (a->day <
b->day)
224 if (a->month >
b->month)
226 else if (a->month <
b->month)
232 if (a->year >
b->year)
234 else if (a->year <
b->year)
238 if (a->year <
b->year)
240 else if (a->year >
b->year)
251static int _datetime_ymd_to_ddays(
const DateTime *dtymd,
double *days)
257 if (dtymd->positive) {
258 *days = dtymd->day - 1;
259 for (mo = dtymd->month - 1; mo > 0; mo--) {
262 for (yr = dtymd->year - 1; yr > 0; yr--) {
267 for (yr = dtymd->year - 1; yr > 0; yr--) {
270 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);.