Aug
25

Day of week for historical dates earlier than 1760

AmR Ical Events List   ,
Off

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);
}

Related posts:

  1. Get the next, or previous day of week from the current date Given a date, get the next or previous Monday, or Tuesday etc from the given date. This is useful when...
  2. Calculate date from day of year in php Here  is a simple first of several notes on useful date functions.  This function accepts  a year  (YYYY) and a...
  3. Gift photo calendar using Google ical files Use your ical feed calendars (google or other (others by importing into google)) and your own photo's to generate a...
  4. Comparison of Event Calendar Plug-ins We are thinking of converting the school’s website from typo3 to wordpress to make it easier for staff and parents...

WP Questions

Preferred Web Host

Web hosting by ICDSoft Icdsoft - Why? They are good and reasonable, used them since 2001. Read more