litesoft
@ 851
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package org.litesoft.core.typeutils.gregorian; import java.util.*; import org.litesoft.core.simpletypes.temporal.*; public class Dates { public static Date now() { return new Date(); } public static SimpleDate forceEndOfMonth( SimpleDate pSimpleDate ) { return (pSimpleDate == null) ? null : pSimpleDate.forceEndOfMonth(); } /** * Returns null if a valid date, or error text if not! */ public static String checkValidity( int pYear, int pMonth, int pDay ) { Month zMonth = Month.fromMonthNumber( pMonth ); if ( zMonth == null ) { return "Invalid month: " + pMonth; } if ( pDay < 1 ) { return "Invalid day: " + pDay; } int maxDaysInMonth = zMonth.daysIn( pYear ); if ( maxDaysInMonth < pDay ) { return zMonth.name() + " " + pYear + " only has " + maxDaysInMonth + ", attempted to set days to: " + pDay; } return null; } } |