hlship / tapx

Extensions to Tapestry 5
http://tapestry.formos.com/projects/tapx/
29 stars 7 forks source link

Problems when date format contains %k #8

Closed jochenberger closed 13 years ago

jochenberger commented 14 years ago

A format string containing %k (hour 0-23, not padded) resulted in 0 being printed as '%k' due to 0 being interpreted as false in JavaScript. When s["%k"] is 0, the anonymous function in line 1780 of calendar.js will return (0 || par), which is par, which is "%k".

I still neither know how to properly provide patches nor how to format code inside a ticket, so here comes an ugly inline patch again.

From 035374f649f3a84b6a23b5374671c0dfa02bb9e0 Mon Sep 17 00:00:00 2001
From: Jochen Berger <fooberger@googlemail.com>
Date: Mon, 23 Aug 2010 13:52:52 +0200
Subject: [PATCH 2/2] a format string containing %k (hour 0-23, not padded) resulted in 0 being printed as '%k' due to 0 being interpreted as false in JavaScript

---
 .../tapx/datefield/jscalendar-1.0/calendar.js      |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tapx-datefield/src/main/resources/com/howardlewisship/tapx/datefield/jscalendar-1.0/calendar.js b/tapx-datefield/src/main/resources/com/howardlewisship/tapx/datefield/jscalendar-1.0/calendar.js
index 0f4f72b..0140fad 100644
--- a/tapx-datefield/src/main/resources/com/howardlewisship/tapx/datefield/jscalendar-1.0/calendar.js
+++ b/tapx-datefield/src/main/resources/com/howardlewisship/tapx/datefield/jscalendar-1.0/calendar.js
@@ -1753,7 +1753,7 @@ Date.prototype.print = function (str) {
    s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
    s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
    s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
-   s["%k"] = hr;       // hour, range 0 to 23 (24h format)
+   s["%k"] = '' + hr;      // hour, range 0 to 23 (24h format)
    s["%l"] = ir;       // hour, range 1 to 12 (12h format)
    s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
    s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
-- 
1.7.0.4
jochenberger commented 14 years ago

committed to my fork: http://github.com/jochenberger/tapx/commit/ad9e3f0008322fc06e9491cd00e1fb6983e74706

hlship commented 13 years ago

Fixed by 5cf58d7aab70d1bb447bd692773debd4cedd3d8d