]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/DateSelector.java
fix: output DoB as date-only
[gigi.git] / src / org / cacert / gigi / output / DateSelector.java
index f98ec8fa6993e9e349848c8f40e02f13a827adb6..20939e499363f6f15006491f25209b05d9fc43f8 100644 (file)
@@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Outputable;
 
 public class DateSelector implements Outputable {
 
@@ -23,7 +24,7 @@ public class DateSelector implements Outputable {
         Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTF"));
         cal.setTime(date);
         this.day = cal.get(Calendar.DAY_OF_MONTH);
-        this.month = cal.get(Calendar.MONTH);
+        this.month = cal.get(Calendar.MONTH) + 1;
         this.year = cal.get(Calendar.YEAR);
     }
 
@@ -39,6 +40,8 @@ public class DateSelector implements Outputable {
 
     private int year;
 
+    private static ThreadLocal<SimpleDateFormat> fmt = new ThreadLocal<>();
+
     @Override
     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
         out.print("<nobr>");
@@ -128,4 +131,15 @@ public class DateSelector implements Outputable {
         return new java.sql.Date(gc.getTime().getTime());
     }
 
+    public static SimpleDateFormat getDateFormat() {
+        SimpleDateFormat local = fmt.get();
+        if (local == null) {
+            local = new SimpleDateFormat("yyyy-MM-dd");
+            local.setLenient(false);
+            local.setTimeZone(TimeZone.getTimeZone("UTC"));
+            fmt.set(local);
+        }
+        return local;
+    }
+
 }