Friday, January 30, 2015

Re: Possible performance enhancements for CalendarUtil.getDaysBetween()

Your implementation does not have same behavior as the original GWT one.

GWTs implementation resets hours, minutes, seconds and milliseconds while your implementation only resets milliseconds AND you reset them wrong as well :) For negative getTime() your calculation moves time to the next second into the future which is wrong because when you reset time you always want to go into the past (so you do not modify the actual day accidentally)

As you only have modified the way aTime and bTime are calculated I have printed them for current GWT implementation and your new implementation. See output:

start: 1969-12-31 22:30:30.500
end: 1970-01-02 15:30:30.500

current GWT aTime: -90000000 => Date: 1969-12-31 00:00:00.000
current GWT bTime: 82800000 => Date: 1970-01-02 00:00:00.000
current GWT days between: 2

new aTime: -8969000 => Date: 1969-12-31 22:30:31.000
new bTime: 138630000 => Date: 1970-01-02 15:30:30.000
new days between: 1

As you can see your implementation does not reset the full time and your millisecond reset moves the start date 500ms into the future. 

GWT had the same millisecond reset bug until I fixed it in https://gwt-review.googlesource.com/#/c/7462/3 
This bug has caused some exceptions in DatePicker for dates that are within 1000ms before epoch as described in the corresponding bug report: https://code.google.com/p/google-web-toolkit/issues/detail?id=8653


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment