1 /*
2 * Copyright 2012 Olivier Godineau
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 * License for the specific language governing permissions and limitations under
12 * the License.
13 */
14 package olg.csv.bean.formatter;
15
16 import java.text.DateFormat;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
19 import java.util.Locale;
20
21 /**
22 * Class dedicated in Date formatting.
23 *
24 */
25 public final class DateFormatter extends Formatter<Date> {
26 /**
27 * The date format.
28 */
29 private final DateFormat dateFormat;
30 // TODO s'assurer que le dateformatter convient dans le cas de classe enfant
31 // à java.util.Date!!
32 @Override
33 public String toString(Date date) {
34
35 return dateFormat.format(date);
36 }
37
38 /**
39 * Constructs a date formatter with the given pattern and default locale.
40 *
41 * @param pattern
42 * the date pattern. must not be <code>null</code>.
43 */
44 public DateFormatter(String pattern) {
45 super();
46 dateFormat = new SimpleDateFormat(pattern);
47 }
48
49 /**
50 *
51 * @param pattern
52 * the date pattern. Must not be <code>null</code>.
53 * @param locale
54 * the locale. Must not be <code>null</code>.
55 */
56 public DateFormatter(String pattern, Locale locale) {
57 super();
58 dateFormat = new SimpleDateFormat(pattern, locale);
59 }
60
61 }