1 package org.kuali.ole.deliver.service;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.StringTokenizer;
6
7
8
9
10 public class DateFormatHelper {
11
12 private static DateFormatHelper dateFormatHelper;
13 private static Map map;
14
15 private DateFormatHelper() {
16 map = new HashMap();
17 map.put("1", "Jan");
18 map.put("01", "Jan");
19 map.put("2", "Feb");
20 map.put("02", "Feb");
21 map.put("3", "Mar");
22 map.put("03", "Mar");
23 map.put("4", "Apr");
24 map.put("04", "Apr");
25 map.put("5", "May");
26 map.put("05", "May");
27 map.put("6", "Jun");
28 map.put("06", "Jun");
29 map.put("7", "Jul");
30 map.put("07", "Jul");
31 map.put("8", "Aug");
32 map.put("08", "Aug");
33 map.put("9", "Sep");
34 map.put("09", "Sep");
35 map.put("10", "Oct");
36 map.put("11", "Nov");
37 map.put("12", "Dec");
38 }
39
40 public static DateFormatHelper getInstance() {
41 if (null == dateFormatHelper) {
42 dateFormatHelper = new DateFormatHelper();
43 }
44 return dateFormatHelper;
45 }
46
47 public String generateDateStringsForMySQL(String dateString) {
48 StringBuilder formattedDate = new StringBuilder();
49
50 StringTokenizer stringTokenizer = new StringTokenizer(dateString, "/");
51 while (stringTokenizer.hasMoreTokens()) {
52 String month = stringTokenizer.nextToken();
53 String day = stringTokenizer.nextToken();
54 String year = stringTokenizer.nextToken();
55 formattedDate.append("'").append(month).append(",").append(day).append(",").append(year).append("'").append(",'").append
56 ("%m,%d,%Y").append("'");
57 }
58 return formattedDate.toString();
59 }
60
61 public String generateDateStringsForOracle(String dateString) {
62 StringBuilder formattedDate = new StringBuilder();
63
64 StringTokenizer stringTokenizer = new StringTokenizer(dateString, "/");
65 while (stringTokenizer.hasMoreTokens()) {
66 String month = stringTokenizer.nextToken();
67 String day = stringTokenizer.nextToken();
68 String year = stringTokenizer.nextToken();
69 formattedDate.append(day).append("-").append(getOracleMonth(month)).append("-").append(year);
70 }
71 return formattedDate.toString();
72 }
73
74
75 private String getOracleMonth(String month) {
76
77 return (String) map.get(month);
78 }
79
80 }