[dev] Off-by-one in Kronolith new-event JavaScript

John Morrissey jwm@horde.net
Fri Oct 25 15:25:36 2002


I tried creating a new event in Kronolith that began on 31 Oct at 23:00 and
ended on 1 Nov at 01:00, but the JavaScript complained that the end date was
before the start date.

Looks like there's an off-by-one error - Date.UTC() expects a zero-based
month. It tries to generate the date "31 Nov", which it wraps to 1 December,
causing the problem above. The patch below seems to fix it; it's been tested
with Mozilla 1.2b and IE 5.2 under Mac OS X.

john

Index: javascript.inc
===================================================================
RCS file: /repository/kronolith/templates/edit/javascript.inc,v
retrieving revision 1.17
diff -u -u -r1.17 javascript.inc
--- javascript.inc	4 Sep 2002 20:53:31 -0000	1.17
+++ javascript.inc	25 Oct 2002 01:52:53 -0000
@@ -152,12 +152,12 @@
     }
 <?php endif; ?>
     var startDate = Date.UTC(form.start_year[form.start_year.selectedIndex].value,
-                             form.start_month[form.start_month.selectedIndex].value,
+                             form.start_month[form.start_month.selectedIndex].value - 1,
                              form.start_day[form.start_day.selectedIndex].value,
                              startHour,
                              form.start_min[form.start_min.selectedIndex].value);
     var endDate = Date.UTC(form.end_year[form.end_year.selectedIndex].value,
-                           form.end_month[form.end_month.selectedIndex].value,
+                           form.end_month[form.end_month.selectedIndex].value - 1,
                            form.end_day[form.end_day.selectedIndex].value,
                            endHour,
                            form.end_min[form.end_min.selectedIndex].value);

-- 
John Morrissey          _o            /\         ----  __o
jwm@horde.net        _-< \_          /  \       ----  <  \,
www.horde.net/    __(_)/_(_)________/    \_______(_) /_(_)__