1 package com.github.mygreen.supercsv.cellprocessor.format;
2
3 import java.text.SimpleDateFormat;
4 import java.util.Locale;
5 import java.util.TimeZone;
6
7
8
9
10
11
12
13
14 public class SimpleDateFormatBuilder {
15
16 private String pattern;
17
18 private Locale locale;
19
20 private TimeZone timeZone;
21
22 private boolean lenient;
23
24
25
26
27
28
29 public static SimpleDateFormatBuilder create(final String pattern) {
30 return new SimpleDateFormatBuilder(pattern);
31 }
32
33 private SimpleDateFormatBuilder(final String pattern) {
34 this.pattern = pattern;
35 this.locale = Locale.getDefault();
36 this.timeZone = TimeZone.getDefault();
37 this.lenient = false;
38 }
39
40
41
42
43
44 public SimpleDateFormat build() {
45
46 final SimpleDateFormat formatter;
47 if(locale == null) {
48 formatter = new SimpleDateFormat(pattern);
49 } else {
50 formatter = new SimpleDateFormat(pattern, locale);
51 }
52
53 if(timeZone != null) {
54 formatter.setTimeZone(timeZone);
55 }
56 formatter.setLenient(lenient);
57
58 return formatter;
59
60 }
61
62 public SimpleDateFormatBuilder locale(final Locale locale) {
63 this.locale = locale;
64 return this;
65 }
66
67 public SimpleDateFormatBuilder timeZone(final TimeZone timeZone) {
68 this.timeZone = timeZone;
69 return this;
70 }
71
72 public SimpleDateFormatBuilder lenient(final boolean lenient) {
73 this.lenient = lenient;
74 return this;
75 }
76
77 }