MH42 / gwt-cal

Automatically exported from code.google.com/p/gwt-cal
0 stars 0 forks source link

DateUtils monthsAdd and daysInMonth #95

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Description of the new feature:
Two utility functions we have use for in our project is to calculate the number 
of days in a given month and also to be able to add or subtract months to a 
date.

Code / psuedo-code:

These works for us:

    @SuppressWarnings("deprecation")
    public static Date monthsAdd(Date date, int months) {
        return new Date(date.getYear(), date.getMonth() + months, Math.min(daysInMonth(date, months), date.getDate()));
    }

    @SuppressWarnings("deprecation")
    private static int daysInMonth(Date date, int months) {
        return 32 - new Date(date.getYear(), date.getMonth()+ months, 32).getDate();
    }

Original issue reported on code.google.com by CoB...@gmail.com on 1 Nov 2010 at 11:37

GoogleCodeExporter commented 8 years ago
Implemented variant methods in rev419
- addDays
- addWeeks
- addMonths
- daysInPeriod
- daysInMonth

Original comment by ctasada on 27 Jun 2012 at 10:34