Changeset 553 for trunk/grails-app


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

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

Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/TaskDetailedController.groovy

    r552 r553  
    809809        result.today.year = dateUtilService.getYearFromDate(result.today.date)
    810810        result.nextMonth = [:]
    811         result.nextMonth.date = dateUtilService.getNextMonth(showDate)
     811        result.nextMonth.date = dateUtilService.plusMonth(showDate)
    812812        result.nextMonth.month = dateUtilService.getMonthFromDate(result.nextMonth.date)
    813813        result.nextMonth.year = dateUtilService.getYearFromDate(result.nextMonth.date)
    814814        result.previousMonth =  [:]
    815         result.previousMonth.date = dateUtilService.getPreviousMonth(showDate)
     815        result.previousMonth.date = dateUtilService.plusMonth(showDate, -1)
    816816        result.previousMonth.month = dateUtilService.getMonthFromDate(result.previousMonth.date)
    817817        result.previousMonth.year = dateUtilService.getYearFromDate(result.previousMonth.date)
  • 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.