Related to issue 25936: Sidestep Smartclient functions
authorDavid Baz Fayos <david.baz@openbravo.com>
Thu, 22 May 2014 00:17:51 +0200
changeset 23089 6395bf98637f
parent 23088 4083ef59b102
child 23090 f6338addf510
Related to issue 25936: Sidestep Smartclient functions
to ensure that standalone files work properly with other libraries
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js	Wed May 21 23:58:53 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js	Thu May 22 00:17:51 2014 +0200
@@ -114,24 +114,33 @@
 
   // if already a date then return true
   var isADate = Object.prototype.toString.call(OBDate) === '[object Date]',
+      PMIndicator = ' PM',
+      AMIndicator = ' AM',
       is24h = true,
       isPM = false;
   if (isADate) {
     return OBDate;
   }
 
+  if (isc && isc.Time && isc.Time.PMIndicator) {
+    PMIndicator = isc.Time.PMIndicator;
+  }
+  if (isc && isc.Time && isc.Time.AMIndicator) {
+    AMIndicator = isc.Time.AMIndicator;
+  }
+
   dateFormat = OB.Utilities.Date.normalizeDisplayFormat(dateFormat);
   dateFormat = dateFormat.replace(' A', '');
   var dateSeparator = dateFormat.substring(2, 3);
   var timeSeparator = dateFormat.substring(11, 12);
   var isFullYear = (dateFormat.indexOf('%Y') !== -1);
-  if (OBDate.indexOf(isc.Time.PMIndicator) !== 1 || OBDate.indexOf(isc.Time.AMIndicator) !== 1) {
+  if (OBDate.indexOf(PMIndicator) !== 1 || OBDate.indexOf(AMIndicator) !== 1) {
     is24h = false;
   }
-  if (!is24h && OBDate.indexOf(isc.Time.PMIndicator) !== -1) {
+  if (!is24h && OBDate.indexOf(PMIndicator) !== -1) {
     isPM = true;
   }
-  OBDate = OBDate.replace(isc.Time.AMIndicator, '').replace(isc.Time.PMIndicator, '');
+  OBDate = OBDate.replace(AMIndicator, '').replace(PMIndicator, '');
 
   if ((isFullYear ? OBDate.length - 2 : OBDate.length) !== dateFormat.length) {
     return null;
@@ -233,11 +242,20 @@
   dateFormat = OB.Utilities.Date.normalizeDisplayFormat(dateFormat);
 
   var isADate = Object.prototype.toString.call(JSDate) === '[object Date]',
+      PMIndicator = ' PM',
+      AMIndicator = ' AM',
       is24h = true,
       isPM = false;
   if (!isADate) {
     return null;
   }
+
+  if (isc && isc.Time && isc.Time.PMIndicator) {
+    PMIndicator = isc.Time.PMIndicator;
+  }
+  if (isc && isc.Time && isc.Time.AMIndicator) {
+    AMIndicator = isc.Time.AMIndicator;
+  }
   if (dateFormat.toUpperCase().lastIndexOf(' A') !== -1 && dateFormat.toUpperCase().lastIndexOf(' A') === dateFormat.length - 2) {
     is24h = false;
   }
@@ -308,9 +326,9 @@
 
   if (!is24h) {
     if (isPM) {
-      OBDate = OBDate.replace(' A', isc.Time.PMIndicator);
+      OBDate = OBDate.replace(' A', PMIndicator);
     } else {
-      OBDate = OBDate.replace(' A', isc.Time.AMIndicator);
+      OBDate = OBDate.replace(' A', AMIndicator);
     }
   }