Author: adrianc
Date: Wed Jul 8 23:14:15 2009 New Revision: 792353 URL: http://svn.apache.org/viewvc?rev=792353&view=rev Log: Small fix for DateRange.java - made the default range smaller. For some reason, external programs have problems with dates in the range of 2 million BC to 2 million AD. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java?rev=792353&r1=792352&r2=792353&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/DateRange.java Wed Jul 8 23:14:15 2009 @@ -26,9 +26,9 @@ @SuppressWarnings("serial") public class DateRange implements Serializable { /** A <code>Date</code> instance initialized to the earliest possible date.*/ - public static final Date MIN_DATE = new Date(Long.MIN_VALUE); + public static final Date MIN_DATE = UtilDateTime.getEarliestDate(); /** A <code>Date</code> instance initialized to the latest possible date.*/ - public static final Date MAX_DATE = new Date(Long.MAX_VALUE); + public static final Date MAX_DATE = UtilDateTime.getLatestDate(); /** A <code>DateRange</code> instance initialized to the widest possible range of dates.*/ public static final DateRange FullRange = new DateRange(); Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java?rev=792353&r1=792352&r2=792353&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java Wed Jul 8 23:14:15 2009 @@ -1138,4 +1138,31 @@ Calendar cal = UtilDateTime.toCalendar(stamp, timeZone, locale); return cal.get(Calendar.YEAR); } + + public static Date getEarliestDate() { + // According to java.util.Calendar docs, earliest accurate date + // using Gregorian calendar is March 1, 4 AD. + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + cal.set(Calendar.YEAR, 4); + cal.set(Calendar.MONTH, Calendar.MARCH); + cal.set(Calendar.DAY_OF_MONTH, 1); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + public static Date getLatestDate() { + // Return last day of 2999 AD. + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + cal.set(Calendar.YEAR, 2999); + cal.set(Calendar.MONTH, cal.getActualMaximum(Calendar.MONTH)); + cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + cal.set(Calendar.MILLISECOND, 999); + return cal.getTime(); + } } |
Free forum by Nabble | Edit this page |