8 #include <grass/datetime.h> 
   43 static int _datetime_ymd_to_ddays(
const DateTime *, 
double *);
 
   44 static int _datetime_compare(
const DateTime *, 
const DateTime *);
 
   83     DateTime tb, ta, *early, *late;
 
  101                                   "only one opperand contains valid timezone");
 
  106                       ta.to < DATETIME_DAY ? DATETIME_YEAR : DATETIME_DAY,
 
  108     compare = _datetime_compare(&ta, &tb);
 
  112         result->positive = 1;
 
  114     else if (compare < 0) {
 
  117         result->positive = 0;
 
  127         if (ta.positive == tb.positive) {
 
  129             result->year = abs(late->year - early->year);
 
  132             result->year = late->year + early->year - 2;
 
  134         dm = late->month - early->month;
 
  139             result->month = dm + 12;
 
  144         double latedays, earlydays;
 
  147         _datetime_ymd_to_ddays(early, &earlydays);
 
  149         erel.day = earlydays;
 
  150         erel.hour = early->hour;
 
  151         erel.minute = early->minute;
 
  152         erel.second = early->second;
 
  155         _datetime_ymd_to_ddays(late, &latedays);
 
  158         lrel.hour = late->hour;
 
  159         lrel.minute = late->minute;
 
  160         lrel.second = late->second;
 
  166         result->day = erel.day;
 
  167         result->hour = erel.hour;
 
  168         result->minute = erel.minute;
 
  169         result->second = erel.second;
 
  184 static int _datetime_compare(
const DateTime * a, 
const DateTime * 
b)
 
  188     if (a->positive && !b->positive)
 
  190     else if (b->positive && !a->positive)
 
  194     for (i = a->from; i <= a->to; i++) {
 
  197         case DATETIME_SECOND:
 
  198             if (a->second > b->second)
 
  200             else if (a->second < b->second)
 
  204         case DATETIME_MINUTE:
 
  205             if (a->minute > b->minute)
 
  207             else if (a->minute < b->minute)
 
  212             if (a->hour > b->hour)
 
  214             else if (a->hour < b->hour)
 
  221             else if (a->day < b->day)
 
  226             if (a->month > b->month)
 
  228             else if (a->month < b->month)
 
  234                 if (a->year > b->year)
 
  236                 else if (a->year < b->year)
 
  240                 if (a->year < b->year)
 
  242                 else if (a->year > b->year)
 
  255 static int _datetime_ymd_to_ddays(
const DateTime * dtymd, 
double *days)
 
  262     if (dtymd->positive) {
 
  263         *days = dtymd->day - 1; 
 
  264         for (mo = dtymd->month - 1; mo > 0; mo--) {     
 
  267         for (yr = dtymd->year - 1; yr > 0; yr--) {      
 
  272         for (yr = dtymd->year - 1; yr > 0; yr--) {      
 
  275         for (mo = 12; mo >= dtymd->month; mo--) {       
 
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_type(DateTime *dt, int mode, int from, int to, int fracsec)
int datetime_days_in_year(int year, int ad)
returns the number of days in 'year' 
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...
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 ...
void datetime_copy(DateTime *dst, const DateTime *src)
Copies the DateTime [into/from ???] src. 
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);. 
int datetime_difference(const DateTime *a, const DateTime *b, DateTime *result)
This performs the formula: result = a - b;. 
void datetime_invert_sign(DateTime *dt)
int datetime_days_in_month(int year, int month, int ad)
returns number of days in 'month' of a particular 'year' 
int datetime_in_interval_year_month(int x)
int datetime_set_increment_type(const DateTime *src, DateTime *incr)
src must be legal This is a convenience routine which is implemented as follows: