[hermes] PATCH: Configure start-of-week, take 2

Jason M. Felice jfelice at cronosys.com
Mon Jul 14 07:12:03 PDT 2003


Now a preference instead of a config option.

-- 
 Jason M. Felice
 Cronosys, LLC <http://www.cronosys.com/>
 216.221.4600 x302
-------------- next part --------------
? lib/api.php
Index: config/prefs.php.dist
===================================================================
RCS file: /repository/hermes/config/prefs.php.dist,v
retrieving revision 1.1
diff -u -u -r1.1 prefs.php.dist
--- config/prefs.php.dist	19 Jul 2002 22:22:00 -0000	1.1
+++ config/prefs.php.dist	14 Jul 2003 14:09:31 -0000
@@ -7,6 +7,12 @@
     'desc' => _("Set the your preferred display language."),
     'members' => array('language'));
 
+$prefGroups['period'] = array(
+    'column' => _("Other Options"),
+    'label' => _("Period Options"),
+    'desc' => _("Configure start of week."),
+    'members' => array('start_of_week'));
+
 
 // user language
 $_prefs['language'] = array(
@@ -15,4 +21,20 @@
     'shared' => true,
     'type' => 'select',
     'desc' => _("Select your preferred language:")
+);
+
+$_prefs['start_of_week'] = array(
+    'value' => '1',
+    'locked' => false,
+    'shared' => true,
+    'type' => 'enum',
+    'enum' => array(
+        '0' => _("Sunday"),
+        '1' => _("Monday"),
+        '2' => _("Tuesday"),
+        '3' => _("Wednesday"),
+        '4' => _("Thursday"),
+        '5' => _("Friday"),
+        '6' => _("Saturday")),
+    'desc' => _("What day does the week start on?")
 );
Index: lib/Hermes.php
===================================================================
RCS file: /repository/hermes/lib/Hermes.php,v
retrieving revision 1.7
diff -u -u -r1.7 Hermes.php
--- lib/Hermes.php	11 Jul 2003 20:23:51 -0000	1.7
+++ lib/Hermes.php	14 Jul 2003 14:09:31 -0000
@@ -52,15 +52,9 @@
 
     function getDayOfWeek($timestamp)
     {
-        // Compensate for date('w') returning 0 for Sunday, when weeks
-        // should start on Monday.
-        $dow = date('w', $timestamp);
-        if ($dow == 0) {
-            $dow = 6;
-        } else {
-            $dow--;
-        }
-        return $dow;
+        // Return 0-6, indicating the position of $timestamp in the period.
+        $dow = 7 + date('w', $timestamp) - $GLOBALS['prefs']->getValue('start_of_week');
+        return ($dow % 7);
     }
 
     function getCurrentTimestamp()


More information about the hermes mailing list