[hermes] PATCH: Sunday display/submit fix, take two.

Jason M. Felice jfelice at cronosys.com
Fri Jul 11 12:15:07 PDT 2003


Creates Hermes::getDayOfWeek() and Hermes::getEndOfWeekStamp(), fixes date
calculation logic.

-- 
 Jason M. Felice
 Cronosys, LLC <http://www.cronosys.com/>
 216.221.4600 x302
-------------- next part --------------
? lib/api.php
Index: edit.php
===================================================================
RCS file: /repository/hermes/edit.php,v
retrieving revision 1.9
diff -u -u -r1.9 edit.php
--- edit.php	23 May 2003 14:44:28 -0000	1.9
+++ edit.php	11 Jul 2003 19:13:08 -0000
@@ -33,7 +33,7 @@
 
 $timestamp = Hermes::getCurrentTimestamp();
 $startofweek = Hermes::getStartOfWeekStamp($timestamp);
-$endofweek = $startofweek + (6 * 86400);
+$endofweek = Hermes::getEndOfWeekStamp($timestamp);
 
 $title = sprintf(_("Edit Time for %s to %s"), strftime('%x', $startofweek), strftime('%x', $endofweek));
 require HERMES_TEMPLATES . '/common-header.inc';
Index: submit.php
===================================================================
RCS file: /repository/hermes/submit.php,v
retrieving revision 1.7
diff -u -u -r1.7 submit.php
--- submit.php	23 May 2003 14:44:30 -0000	1.7
+++ submit.php	11 Jul 2003 19:13:08 -0000
@@ -39,7 +39,7 @@
 
 $timestamp = Hermes::getCurrentTimestamp();
 $startofweek = Hermes::getStartOfWeekStamp($timestamp);
-$endofweek = $startofweek + (6 * 86400);
+$endofweek = Hermes::getEndOfWeekStamp($timestamp);
 
 $title = sprintf(_("Submit Time for %s to %s"), strftime('%x', $startofweek), strftime('%x', $endofweek));
 require HERMES_TEMPLATES . '/common-header.inc';
Index: time.php
===================================================================
RCS file: /repository/hermes/time.php,v
retrieving revision 1.16
diff -u -u -r1.16 time.php
--- time.php	19 Jun 2003 18:47:33 -0000	1.16
+++ time.php	11 Jul 2003 19:13:08 -0000
@@ -34,7 +34,7 @@
 
 $timestamp = Hermes::getCurrentTimestamp();
 $startofweek = Hermes::getStartOfWeekStamp($timestamp);
-$endofweek = $startofweek + (6 * 86400);
+$endofweek = Hermes::getEndOfWeekStamp($timestamp);
 
 $title = sprintf(_("Time Entry for %s to %s"), strftime('%x', $startofweek), strftime('%x', $endofweek));
 require HERMES_TEMPLATES . '/common-header.inc';
Index: lib/Hermes.php
===================================================================
RCS file: /repository/hermes/lib/Hermes.php,v
retrieving revision 1.6
diff -u -u -r1.6 Hermes.php
--- lib/Hermes.php	16 Jun 2003 23:12:06 -0000	1.6
+++ lib/Hermes.php	11 Jul 2003 19:13:08 -0000
@@ -36,16 +36,31 @@
             $weekstamp = time();
         }
 
+        $dow = Hermes::getDayOfWeek($weekstamp);
+        return mktime(0, 0, 0, date('n', $weekstamp), date('j', $weekstamp) - $dow);
+    }
+
+    function getEndOfWeekStamp($weekstamp = null)
+    {
+        if (is_null($weekstamp)) {
+            $weekstamp = time();
+        }
+
+        $dow = Hermes::getDayOfWeek($weekstamp);
+        return mktime(23, 59, 59, date('n', $weekstamp), date('j', $weekstamp) - $dow + 6);
+    }
+
+    function getDayOfWeek($timestamp)
+    {
         // Compensate for date('w') returning 0 for Sunday, when weeks
         // should start on Monday.
-        $dow = date('w', $weekstamp);
+        $dow = date('w', $timestamp);
         if ($dow == 0) {
             $dow = 6;
         } else {
             $dow--;
         }
-
-        return mktime(0, 0, 0, date('n', $weekstamp), date('j', $weekstamp) - $dow);
+        return $dow;
     }
 
     function getCurrentTimestamp()


More information about the hermes mailing list