SemanticMediawiki Extensions

From HackerspaceWiki
Jump to: navigation, search

Note: this does not work with SMW 1.5.3 or later.

Add weekdayofmonth unit to recurring events[edit]

Explanation[edit]

Instead of having events only recur on specific dates of a month, (i.e. every 6th), this code allows to have them recur on every xth Weekday of a month. (i.e. every first Saturday)

Acceptance into SMW repository is pending.

Code[edit]

Index: SMW_ParserExtensions.php
===================================================================
--- SMW_ParserExtensions.php        (revision 63234)
+++ SMW_ParserExtensions.php        (working copy)
@@ -416,6 +416,14 @@
                                 $date_str = "$cur_year-$cur_month-$cur_day $cur_time";
                                 $cur_date = SMWDataValueFactory::newTypeIDValue('_dat', $date_str);
                                 $cur_date_jd = $cur_date->getNumericValue();
+                        } elseif($unit == 'xofmonth') {
+                                $check_month = $cur_date->getMonth();
+                                $cur_date_jd += 28 * $period;
+                                $cur_date = SMWDataValueFactory::newTypeIDValue('_dat', $cur_date_jd);
+                                if ($cur_date->getMonth() != (($check_month + $period) % 12 )){
+                                        $cur_date_jd += 7;        // add another week
+                                        $cur_date = SMWDataValueFactory::newTypeIDValue('_dat', $cur_date_jd);
+                                }
                         } else { // $unit == 'day' or 'week'
                                 // assume 'day' if it's none of the above
                                 $cur_date_jd += ($unit === 'week') ? 7 * $period : $period;

Example[edit]

Contact[edit]

--Kwisatz 22:12, 9 March 2010 (UTC)