|
From: <ma...@us...> - 2010-03-01 18:17:19
|
Revision: 288
http://objectlabkit.svn.sourceforge.net/objectlabkit/?rev=288&view=rev
Author: marchy
Date: 2010-03-01 18:17:11 +0000 (Mon, 01 Mar 2010)
Log Message:
-----------
refactoring to remove duplicate code in test case, and renaming of field.
Modified Paths:
--------------
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java 2010-03-01 18:16:43 UTC (rev 287)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java 2010-03-01 18:17:11 UTC (rev 288)
@@ -88,13 +88,7 @@
if (dateStr == null) {
return createCalendar(null).getTime();
}
- try {
- final Date date = SDF.parse(dateStr);
- final Calendar cal = getCal(date);
- return cal.getTime();
- } catch (final ParseException e) {
- throw new IllegalArgumentException("\"" + dateStr + "\"" + " is an invalid date, the pattern is : " + DATE_PATTERN);
- }
+ return getCal(dateStr).getTime();
}
// -----------------------------------------------------------------------
@@ -107,25 +101,29 @@
/**
* get a new Calendar based on the string date.
- * @param str
+ * @param dateStr
* the date string
* @return a new Calendar
* @throws IllegalArgumentException
* if the string cannot be parsed.
*/
- public static Calendar createCalendar(final String str) {
- if (str == null) {
+ public static Calendar createCalendar(final String dateStr) {
+ if (dateStr == null) {
return blastTime(Calendar.getInstance());
}
+ return getCal(dateStr);
+ }
+
+ public static Calendar getCal(final String dateStr) {
try {
- final Date date = SDF.parse(str);
+ final Date date = SDF.parse(dateStr);
final Calendar cal = getCal(date);
return cal;
} catch (final ParseException e) {
- throw new IllegalArgumentException("\"" + str + "\"" + " is an invalid date, the pattern is : " + DATE_PATTERN);
- }
+ throw new IllegalArgumentException("\"" + dateStr + "\"" + " is an invalid date, the pattern is : " + DATE_PATTERN);
+ }
}
-
+
/**
* Get a Calendar object for a given Date representation.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|