Wednesday, August 31, 2016

CalenderUtil Date Math BUG - GWT 2.8 RC2

We have run into what looks like a date math bug for today's date:

Here is our logged output:

[butter] Wed Aug 31 16:15:15 GMT-400 2016 Tester Date: Wed Aug 31 16:15:15 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 mth: 8
[butter] Wed Aug 31 16:15:15 GMT-400 2016 mth: 7
[butter] Wed Aug 31 16:15:15 GMT-400 2016 q: 7
[butter] Wed Aug 31 16:15:15 GMT-400 2016 qMth: 7
[butter] Wed Aug 31 16:15:15 GMT-400 2016 qMth - mth: 1
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Date (now): Wed Aug 31 16:15:15 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Date (addMonthsToDate): Sat Oct 01 16:15:15 GMT-400 2016, 1
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Date:(setToFirstDayOfMonth) Sat Oct 01 00:00:00 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Date(addMonthsToDate+1): Tue Nov 01 00:00:00 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Date(addDaysToDate-1): Mon Oct 31 00:00:00 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 Tester setDateToLastOfQtr: Mon Oct 31 00:00:00 GMT-400 2016
[butter] Wed Aug 31 16:15:15 GMT-400 2016 - on butter module load - 2.8.0-rc2

Here is the code:

    public static void setDateToLastOfQtr(Date date) {
        // Magic Mike's Fist Qtr Fix --> ask him
        int mth = Integer.valueOf(DateTimeFormat.getFormat("M").format(date));
        Api.log("mth: "+mth);
        mth--;
        Api.log("mth: "+mth);
       
        int q = mth / 3;
        Api.log("q: "+mth);
       
        int qMth = (q * 3) + 2;
        Api.log("qMth: "+mth);

        Api.log("qMth - mth: "+(qMth-mth));
        Api.log("Date (now): "+date);
        CalendarUtil.addMonthsToDate(date, qMth - mth);
        Api.log("Date (addMonthsToDate): "+date+", "+(qMth-mth));
        CalendarUtil.setToFirstDayOfMonth(date);
        Api.log("Date:(setToFirstDayOfMonth) "+date);
        CalendarUtil.addMonthsToDate(date, 1);
        Api.log("Date(addMonthsToDate+1): "+date);
        CalendarUtil.addDaysToDate(date, -1);
        Api.log("Date(addDaysToDate-1): "+date);
    }

No comments:

Post a Comment