Ignore:
Timestamp:
May 31, 2010, 1:54:53 PM (14 years ago)
Author:
gav
Message:

Small refator of DateUtilService.
New plusMonth() replaces getNextMonth and getPreviousMonth().
Clarify getDayFromDate() to getDayOfMonthFromDate().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/DateUtilService.groovy

    r552 r553  
    7777
    7878    /**
    79     * Get the date one month in the future.
    80     * @param date The Date object to start with.
    81     * @returns A Date object one month in the future.
     79    * Get the date plus x weeks.
     80    * @param date The Date object to start with, defaults to today.
     81    * @param plusYears The number of weeks to add, defaults to 1.
     82    * @returns A Date object adjusted by x weeks.
    8283    */
    83     public static Date getNextMonth(Date date) {
     84    public static Date plusWeek(Date date = new Date(), Integer plusWeeks = 1) {
    8485        use(TimeCategory) {
    85             date + 1.months
     86            date + plusWeeks.weeks
    8687        }
    8788    }
    8889
    8990    /**
    90     * Get the date one month ago.
    91     * @param date The Date object to start with.
    92     * @returns A Date object one month ago.
     91    * Get the date plus x months.
     92    * @param date The Date object to start with, defaults to today.
     93    * @param plusYears The number of months to add, defaults to 1.
     94    * @returns A Date object adjusted by x months.
    9395    */
    94     public static Date getPreviousMonth(Date date) {
     96    public static Date plusMonth(Date date = new Date(), Integer plusMonths = 1) {
    9597        use(TimeCategory) {
    96             date - 1.months
     98            date + plusMonths.months
    9799        }
    98100    }
     
    133135    * @returns An integer representing the day of the month.
    134136    */
    135     public static Integer getDayFromDate(Date date) {
     137    public static Integer getDayOfMonthFromDate(Date date) {
    136138        Calendar cal = Calendar.instance
    137139        cal.setTime(date)
Note: See TracChangeset for help on using the changeset viewer.