date subpackage

master
Keith Donald 16 years ago
parent b8b84f4f39
commit 065102bca9
  1. 6
      org.springframework.context/src/main/java/org/springframework/ui/format/AnnotationFormatterFactory.java
  2. 3
      org.springframework.context/src/main/java/org/springframework/ui/format/date/DateFormatter.java
  3. 2
      org.springframework.context/src/test/java/org/springframework/ui/binding/BinderTests.java
  4. 35
      org.springframework.context/src/test/java/org/springframework/ui/format/date/DateFormatterTests.java

@ -18,8 +18,8 @@ package org.springframework.ui.format;
import java.lang.annotation.Annotation;
/**
* A factory that creates Formatters to format property values on properties annotated with a particular format {@link Annotation}.
* For example, a <code>CurrencyAnnotationFormatterFactory</code> might create a {@link Formatter} that formats a <code>BigDecimal</code> value set on a property annotated with <code>@CurrencyFormat</code>.
* A factory that creates {@link Formatter formatters} to format property values on properties annotated with a particular format {@link Annotation}.
* For example, a <code>CurrencyAnnotationFormatterFactory</code> might create a <code>Formatter</code> that formats a <code>BigDecimal</code> value set on a property annotated with <code>@CurrencyFormat</code>.
* @author Keith Donald
* @param <A> The type of Annotation this factory uses to create Formatter instances
* @param <T> The type of Object Formatters created by this factory format
@ -33,4 +33,4 @@ public interface AnnotationFormatterFactory<A extends Annotation, T> {
* @return the Formatter to use to format values of properties annotated with the annotation.
*/
Formatter<T> getFormatter(A annotation);
}
}

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.format;
package org.springframework.ui.format.date;
import java.text.DateFormat;
import java.text.ParseException;
@ -23,6 +23,7 @@ import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ui.format.Formatter;
/**
* A formatter for {@link Date} types.

@ -19,7 +19,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.format.DateFormatter;
import org.springframework.ui.format.date.DateFormatter;
import org.springframework.ui.format.number.CurrencyAnnotationFormatterFactory;
import org.springframework.ui.format.number.CurrencyFormat;
import org.springframework.ui.format.number.CurrencyFormatter;

@ -0,0 +1,35 @@
package org.springframework.ui.format.date;
import static org.junit.Assert.assertEquals;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Locale;
import org.junit.Test;
public class DateFormatterTests {
private DateFormatter formatter = new DateFormatter();
@Test
public void formatValue() {
Calendar cal = Calendar.getInstance(Locale.US);
cal.clear();
cal.set(Calendar.YEAR, 2009);
cal.set(Calendar.MONTH, Calendar.JUNE);
cal.set(Calendar.DAY_OF_MONTH, 1);
assertEquals("2009-06-01", formatter.format(cal.getTime(), Locale.US));
}
@Test
public void parseValue() throws ParseException {
Calendar cal = Calendar.getInstance(Locale.US);
cal.clear();
cal.set(Calendar.YEAR, 2009);
cal.set(Calendar.MONTH, Calendar.JUNE);
cal.set(Calendar.DAY_OF_MONTH, 1);
assertEquals(cal.getTime(), formatter.parse("2009-06-01", Locale.US));
}
}
Loading…
Cancel
Save