details: https://code.openbravo.com/erp/devel/pi/rev/04d8ff337b7d
changeset: 16833:04d8ff337b7d
user: Augusto Mauch <augusto.mauch <at> openbravo.com>
date: Wed Jun 13 20:10:44 2012 +0545
summary: Fixes issue 20479: TimeDate filter supports different timezones
The timedate criteria was not sending the UTC offset to the server, making the
support of different time zones impossible. Now the UTC offset is sent along
the timedate criteria, and the server applies it before fetching data from the
database.
diffstat:
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
| 28 +++++++++-
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
| 26 ++++++--
2 files changed, 44 insertions(+), 10 deletions(-)
diffs (115 lines):
diff -r 5a22035bcba6 -r 04d8ff337b7d
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
---
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
Wed Jun 13 13:45:12 2012 +0200
+++
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
Wed Jun 13 20:10:44 2012 +0545
@@ -1102,7 +1102,8 @@
},
convertCriteria: function (criteria) {
- var selectedValues, prop, fld, value, i, criterion, fldName, length;
+ var selectedValues, prop, fld, value, i, j, k, criterion, fldName, length,
today = new Date(),
+ currentTimeZoneOffsetInMinutes = -today.getTimezoneOffset();
if (!criteria) {
criteria = {};
@@ -1186,7 +1187,9 @@
}
}
- // get rid of some unneeded stuff in the criteria
+ // Iterates all the criterias
+ // -If they are not needed, they are removed
+ // -Otherwise, if it is a datetime criteria, the UTC offset in minutes is
added
if (criteria && criteria.criteria) {
var internalCriteria = criteria.criteria;
for (i = (internalCriteria.length - 1); i >= 0; i--) {
@@ -1200,6 +1203,27 @@
}
if (shouldRemove) {
internalCriteria.removeAt(i);
+ } else {
+ var fieldName;
+ //The first name a date time field is filtered, the fieldName is
stored in criteria.criteria[i].criteria[0].fieldName
+ if (criteria.criteria[i].criteria &&
criteria.criteria[i].criteria[0]) {
+ fieldName = criteria.criteria[i].criteria[0].fieldName;
+ } else { //After the first time, the fieldName is stored in
criteria.criteria[i].fieldName
+ fieldName = criteria.criteria[i].fieldName;
+ }
+
+ for (j = 0; j < this.fields.length; j++) {
+ if (this.fields[j].name === fieldName &&
isc.SimpleType.getType(this.fields[j].type).inheritsFrom === "datetime") {
+ if (criteria.criteria[i].criteria) {
+ for (k = 0; k < criteria.criteria[i].criteria.length; k++) {
+ criteria.criteria[i].criteria[k].minutesTimezoneOffset =
currentTimeZoneOffsetInMinutes;
+ }
+ } else {
+ criteria.criteria[i].minutesTimezoneOffset =
currentTimeZoneOffsetInMinutes;
+ }
+ break;
+ }
+ }
}
}
}
diff -r 5a22035bcba6 -r 04d8ff337b7d
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Wed Jun 13 13:45:12 2012 +0200
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
Wed Jun 13 20:10:44 2012 +0545
@@ -129,6 +129,8 @@
// keeps track if during parsing the criteria one or more or's are
encountered.
private int orNesting = 0;
+ private int minutesTimeZoneDiff = 0;
+
private SimpleDateFormat simpleDateFormat = JsonUtils.createDateFormat();
public Entity getEntity() {
@@ -292,6 +294,17 @@
String fieldName = jsonCriteria.getString("fieldName");
Object value = jsonCriteria.has("value") ? jsonCriteria.get("value") :
null;
+ // Retrieves the UTC time zone offset of the client
+ if (jsonCriteria.has("minutesTimezoneOffset")) {
+ int clientMinutesTimezoneOffset =
Integer.parseInt(jsonCriteria.get("minutesTimezoneOffset")
+ .toString());
+ Calendar now = Calendar.getInstance();
+ // Obtains the UTC time zone offset of the server
+ int serverMinutesTimezoneOffset = (now.get(Calendar.ZONE_OFFSET) + now
+ .get(Calendar.DST_OFFSET)) / (1000 * 60);
+ // Obtains the time zone offset between the server and the client
+ minutesTimeZoneDiff = serverMinutesTimezoneOffset -
clientMinutesTimezoneOffset;
+ }
if (operator.equals(OPERATOR_ISNULL) || operator.equals(OPERATOR_NOTNULL))
{
value = null;
@@ -620,27 +633,24 @@
} else if (Date.class.isAssignableFrom(property.getPrimitiveObjectType()))
{
try {
final Date date = simpleDateFormat.parse(value.toString());
+ final Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
// move the date to the beginning of the day
if (isGreaterOperator(operator)) {
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
- return calendar.getTime();
} else if (isLesserOperator(operator)) {
// move the data to the end of the day
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
calendar.set(Calendar.HOUR, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
- return calendar.getTime();
- } else {
- return date;
}
+ // Applies the time zone offset difference between the client and the
server
+ calendar.add(Calendar.MINUTE, minutesTimeZoneDiff);
+ return calendar.getTime();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits