Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(278)

Issue 1898803: CalendarUtil class has division error in addMonthsToDate

Can't Edit
Can't Publish+Mail
Start Review
Created:
4 years, 1 month ago by willseph
Modified:
4 years, 1 month ago
Reviewers:
mdempsky
CC:
skybrian
Base URL:
http://google-web-toolkit.googlecode.com/svn/trunk/
Visibility:
Public.

Description

On line 68 in the CalendarUtil.java file, the calculation for determining the
resulting year after adding a number of months to a date has an error.

Because the Gregorian calendar (used by the java.util.Date library) represents
the year 1900 as 0, a problem occurs when the resulting date should be earlier
than Jan 1900. The issue lies in integer division:

int resultYear = resultMonthCount / 12;

For example, if resultMonthCount is -1, then the resulting year will be 0 (1900)
instead of -1 (1899) like it should be. I am submitting a patch file which
changes this line to the following:

int resultYear = (int) Math.floor(resultMonthCount / 12.0);

This will ensure that the number will result in the correct quotient for both
positive, zero and negative values of resultMonthCount.

Patch Set 1

Unified diffs Side-by-side diffs Delta from patch set Stats Patch
user/src/com/google/gwt/user/datepicker/client/CalendarUtil.java View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 4
willseph
4 years, 1 month ago #1
mdempsky
LGTM
4 years, 1 month ago #2
willseph
On 2013/03/19 16:40:05, mdempsky wrote: > LGTM Sweet!
4 years, 1 month ago #3
mdempsky
4 years, 1 month ago #4
Committed as r11564:
https://code.google.com/p/google-web-toolkit/source/detail?r=11564

(That page shows gwt.mirrorbot as the author, but that should be fixed once the
cache clears.  You can see the correct author information on the changes index
list here: https://code.google.com/p/google-web-toolkit/source/list)
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld revision f51cb906c4ad+