One of the ics files that I encountered in testing my events list plugin came from Google and had a “Zero Year” date in it. There were probably reasons for this and I have to be thankful for the happening – In looking into it I foundthat the php date format function for day of week $dateobj->format(‘w’); “breaks” around the year 1760 and starts returning a “-1”. Since I do have people using my plugin for anniversaries with earlier start dates (It’s not all musical gigs and sporting events!), I felt I needed to cope with it.
I now use the following code, which appears to work when comparing the weekdays using http://www.searchforancestors.com/utility/dayofweek.html
$w = $dateobj->format('w'); if ($w == '-1') $w = get_oldweekdays($dateobj); function get_oldweekdays ($d) { $dummy = new DateTime(); $dummy = clone ($d); date_modify($dummy,'+91500 weeks'); /* add weeks to get us back to a "working" date - a guess from when the date started breaking, plus some extra to be safe */ $w = $dummy->format('w'); return($w); }