php - determine whether DateTime falls on a DateInterval -
i trying determine whether datetime coincides possible occurance of dateinterval. intervals i'm using need allow 'nth xday of next month' type format specifications , i'm not sure such thing possible given conditions.
my basic idea invert dateinterval, apply clone of original datetime, put was, apply again , check if 2 datetime instances equal. if so, occurs on interval:
public static function datefallsonperiod(datetime $date, dateinterval $interval) { $compare = clone $date; // invert period, apply date, uninvert & reapply $interval->invert = 1; $compare->add($interval); $interval->invert = 0; $compare->add($interval); return $date == $compare; } this seemed apply interval twice in same direction, , tried again using ->sub() , ->add(), resulting in fatal error "datetime::sub(): non-special relative time specifications supported subtraction". seems kind of functionality isn't implemented @ all.
does have better ideas, in lieu of ugly & inefficient solution of choosing offset behind start date , iterating forward until we've matched or gone past?
thanks in advance!
one possibility generate unix timestamps datetime , compare integer values.
Comments
Post a Comment