Changeset 476 for trunk/grails-app/services/DateUtilService.groovy
- Timestamp:
- Apr 7, 2010, 1:49:22 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/DateUtilService.groovy
r474 r476 99 99 100 100 /** 101 * Get the date one year in the future. 102 * @param date The Date object to start with. 103 * @returns A Date object one year in the future. 104 */ 105 public static Date getNextYear(Date date) { 106 use(TimeCategory) { 107 date + 1.years 108 } 109 } 110 111 /** 112 * Get the date one year ago. 113 * @param date The Date object to start with. 114 * @returns A Date object one year ago. 115 */ 116 public static Date getPreviousYear(Date date) { 117 use(TimeCategory) { 118 date - 1.years 119 } 120 } 121 122 /** 101 123 * Make a date object from supplied year, month, day values. 102 124 * The Calendar.getInstance() or Calendar.instance factory returns a new calendar instance, usually … … 104 126 * The time fields are set to zero and cal.getTime() or cal.time returns a java.util.Date object. 105 127 * @param year The year as a string or integer. 106 * @param month The month as a string or integer .107 * @param day The day as a string or integer .128 * @param month The month as a string or integer, defaults to 1 (i.e. January). 129 * @param day The day as a string or integer, defaults to 1. 108 130 * @returns A Date object having the given date and all time fields set to 0, so the very start of the given day. 109 131 */ 110 public static Date makeDate(year, month , day) {132 public static Date makeDate(year, month=1, day=1) { 111 133 Calendar cal = Calendar.instance 112 134 cal.clear() … … 116 138 } 117 139 140 /** 141 * Get the day of month from supplied date. 142 * @param date The date to extract the day of month from. 143 * @returns An integer representing the day of the month. 144 */ 145 public static Integer getDayFromDate(Date date) { 146 Calendar cal = Calendar.instance 147 cal.setTime(date) 148 cal.get(Calendar.DAY_OF_MONTH) 149 } 150 151 /** 152 * Get the month from supplied date. 153 * @param date The date to extract the month from. 154 * @returns An integer representing the month. 155 */ 156 public static Integer getMonthFromDate(Date date) { 157 Calendar cal = Calendar.instance 158 cal.setTime(date) 159 cal.get(Calendar.MONTH) + 1 // Stupid month is 0-based, grumble. 160 } 161 162 /** 163 * Get the year from supplied date. 164 * @param date The date to extract the year from. 165 * @returns An integer representing the year. 166 */ 167 public static Integer getYearFromDate(Date date) { 168 Calendar cal = Calendar.instance 169 cal.setTime(date) 170 cal.get(Calendar.YEAR) 171 } 172 118 173 }
Note: See TracChangeset
for help on using the changeset viewer.