Saturday, January 31, 2015

Re: Possible performance enhancements for CalendarUtil.getDaysBetween()

I must admit I didn't spend enough time to fully understand why the gwt original  implementation did all that stuff for resetting time. Many thanks for the detailed explanation.
At the moment I have no access to dev tools, anyway I'm just wondering if there's still room for optimizations without incurring in bugs: i.e. if resetting dates time is needed, then CalendarUtils could keep two private static Date instances instead of instantiating two new dates per call (that should be safe until there's no multithreading)

2015-01-31 3:08 GMT+01:00 Jens <jens.nehlmeier@gmail.com>:
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 a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/OVnGQi0k-Y4/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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