Date and Time rules

E-mail
(3 votes, average 5.00 out of 5)

MetaMod has great support for dates and times. You can make simple rules that publish and unpublish modules at certain dates and times, but that’s just the beginning. Rules like these are great for displaying certain modules during “shopping hours”, radio programme broadcasts, sports seasons etc.

This MetaMod PHP recipe uses the new time and date constants in MetaMod 1.5h. If you haven’t upgraded yet, now’s the time!

Make sure you have set the Time Zone dropdown in MetaMod to your local time zone if you’re relying on time/date related functions.

Any of the following rules can be used independently of the others.
if ( MM_MONTH == 5 ) return 74; /* month of May, any year */
/* 1st Feb 2009 to 24 May 2009 */
if ( MM_DATE >= 20090201 && MM_DATE <= 20090524) return 75;
/* 7:00-9:00 every Sunday */
if ( MM_TIME >= 70000 && MM_TIME < 93000 && MM_DAY_OF_WEEK == 0 ) return 76;
/* every Saturday and Sunday */
if ( MM_DAY_OF_WEEK == 6 || MM_DAY_OF_WEEK == 0 ) return 76;
/* 6PM Friday to midnight Sunday night */
if ( ( MM_DAY_OF_MONTH == 5 && MM_TIME >= 180000 )
     || MM_DAY_OF_WEEK == 6
     || MM_DAY_OF_WEEK == 0 ) return 76;
if ( MM_DAY_OF_MONTH <= 7 ) return 76; /* 1st to 7th day of every month */
// between 9-11AM, 4-6PM and 8-10PM Monday to Friday 
if (
 (MM_DAY_OF_WEEK >= 1 && MM_DAY_OF_WEEK <= 5) &&
  (
   (MM_TIME > 90000 && MM_TIME < 110000 )
   || (MM_TIME > 160000 &&  MM_TIME < 180000 )
   || (MM_TIME > 200000 &&  MM_TIME < 220000 )
  )
 ) {
 return 50;
}