Fixes issue 26262: Dates with negative offsets are formatted properly
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 14 Apr 2014 14:12:57 +0200
changeset 22912 f61bf8d6176d
parent 22911 d80d8cd8e39b
child 22913 7b986e0bf0ef
Fixes issue 26262: Dates with negative offsets are formatted properly

The proper javascript format for dates and datetimes with timezone offset if the following: 2009-12-06T15:59:34+01:00. There if a method in charge of adding the semicolon in the datetime part in case it is missing.

Due to a bug in that method, the semicolon was not being added in dates with negative timezone offset. This resulted in a failure in the parsing of that date in the client side, being the date object actually modified when it was parsed.

In Openbravo there is a safety mechanism that detects if a record has changed based on its updated field. The updated field was being improperly modified in the client, so the safety mechanism was assuming that the record had actually been changed by another user, and was preventing the record from being saved.
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Mon Apr 14 13:32:27 2014 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Mon Apr 14 14:12:57 2014 +0200
@@ -136,8 +136,9 @@
    * @return a colon added in the timezone part: 2009-12-06T15:59:34+01:00
    */
   public static String convertToCorrectXSDFormat(String dateValue) {
-    if (dateValue == null || dateValue.length() < 3 || dateValue.indexOf("+") == -1
-        || dateValue.indexOf("-") == -1) {
+    int idxT = dateValue.indexOf("T");
+    if (dateValue == null || dateValue.length() < 3 || idxT == -1
+        || (dateValue.indexOf("+", idxT) == -1 && dateValue.indexOf("-", idxT) == -1)) {
       return dateValue;
     }
     final int length = dateValue.length();