/** * * return 0/REC_MATCH - the time falls in * -1/REC_ERR - error * 1/REC_NOMATCH - the time falls out */ int check_tmrec(tmrec_p _trp, ac_tm_p _atp, tr_res_p _tsw) { if(!_trp || !_atp || (!_IS_SET(_trp->duration) && !_IS_SET(_trp->dtend))) return REC_ERR; // it is before start date if(_atp->time < _trp->dtstart) return REC_NOMATCH; // compute the duration of the reccurence interval if(!_IS_SET(_trp->duration)) _trp->duration = _trp->dtend - _trp->dtstart; if(_atp->time <= _trp->dtstart+_trp->duration) { if(_tsw) { if(_tsw->flag & TSW_RSET) { if(_tsw->rest>_trp->dtstart+_trp->duration-_atp->time) _tsw->rest = _trp->dtstart+_trp->duration - _atp->time; } else { _tsw->flag |= TSW_RSET; _tsw->rest = _trp->dtstart+_trp->duration - _atp->time; } } return REC_MATCH; } // after the bound of recurrence if(_IS_SET(_trp->until)) { if(_atp->time >= _trp->until + _trp->duration) return REC_NOMATCH; } else { if(!_IS_SET(_trp->freq) && _atp->time >= _trp->dtstart + _trp->duration) return REC_NOMATCH; } // check if the instance of recurence matches the 'interval' if(check_freq_interval(_trp, _atp)!=REC_MATCH) return REC_NOMATCH; if(check_min_unit(_trp, _atp, _tsw)!=REC_MATCH) return REC_NOMATCH; if(check_byxxx(_trp, _atp)!=REC_MATCH) return REC_NOMATCH; return REC_MATCH; }
int check_freq_interval(tmrec_p _trp, ac_tm_p _atp) { int _t0, _t1; struct tm _tm; if(!_trp || !_atp) return REC_ERR; if(!_IS_SET(_trp->freq)) return REC_NOMATCH; if(!_IS_SET(_trp->interval) || _trp->interval==1) return REC_MATCH; switch(_trp->freq) { case FREQ_DAILY: case FREQ_WEEKLY: memset(&_tm, 0, sizeof(struct tm)); _tm.tm_year = _trp->ts.tm_year; _tm.tm_mon = _trp->ts.tm_mon; _tm.tm_mday = _trp->ts.tm_mday; _t0 = (int)mktime(&_tm); memset(&_tm, 0, sizeof(struct tm)); _tm.tm_year = _atp->t.tm_year; _tm.tm_mon = _atp->t.tm_mon; _tm.tm_mday = _atp->t.tm_mday; _t1 = (int)mktime(&_tm); if(_trp->freq == FREQ_DAILY) return (((_t1-_t0)/(24*3600))%_trp->interval==0)? REC_MATCH:REC_NOMATCH; #ifdef USE_YWEEK_U _t0 -= _trp->ts.tm_wday*24*3600; _t1 -= _atp->t.tm_wday*24*3600; #else _t0 -= ((_trp->ts.tm_wday+6)%7)*24*3600; _t1 -= ((_atp->t.tm_wday+6)%7)*24*3600; #endif return (((_t1-_t0)/(7*24*3600))%_trp->interval==0)? REC_MATCH:REC_NOMATCH; case FREQ_MONTHLY: _t0 = (_atp->t.tm_year-_trp->ts.tm_year)*12 + _atp->t.tm_mon-_trp->ts.tm_mon; return (_t0%_trp->interval==0)?REC_MATCH:REC_NOMATCH; case FREQ_YEARLY: return ((_atp->t.tm_year-_trp->ts.tm_year)%_trp->interval==0)? REC_MATCH:REC_NOMATCH; } return REC_NOMATCH; }