Problems when date format contains %k #8

Closed
jochenberger opened this Issue Aug 23, 2010 · 2 comments

Projects

None yet

2 participants

@jochenberger
Collaborator

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
@hlship
Owner
hlship commented Dec 2, 2010

Fixed by 5cf58d7

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment