]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/DateSelector.java
upd: moved the lower year range to 1890 so the age check of the DoB with
[gigi.git] / src / org / cacert / gigi / output / DateSelector.java
index ad1bdf33e3b543da3b64a56fb28ad09627446571..a17532695b3bf074971d835212b9de6f9c4d84ce 100644 (file)
@@ -4,8 +4,6 @@ import java.io.PrintWriter;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
 import java.util.Map;
 import java.util.TimeZone;
 
@@ -14,16 +12,18 @@ import javax.servlet.http.HttpServletRequest;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.util.CalendarUtil;
+import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.HTMLEncoder;
 
 public class DateSelector implements Outputable {
 
     private String[] names;
 
-    public DateSelector(String day, String month, String year, Date date) {
+    public DateSelector(String day, String month, String year, DayDate date) {
         this(day, month, year);
-        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTF"));
-        cal.setTime(date);
+        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+        cal.setTimeInMillis(date.getTime());
         this.day = cal.get(Calendar.DAY_OF_MONTH);
         this.month = cal.get(Calendar.MONTH) + 1;
         this.year = cal.get(Calendar.YEAR);
@@ -115,10 +115,15 @@ public class DateSelector implements Outputable {
     }
 
     public boolean isValid() {
-        if ( !(1900 < year && 1 <= month && month <= 12 && 1 <= day && day <= 32)) {
+        if ( !(1890 < year && 1 <= month && month <= 12 && 1 <= day && day <= 32)) {
             return false;
         }
-        return true; // TODO checkdate
+
+        if ( !CalendarUtil.isDateValid(year, month, day)) {
+            return false;
+        }
+
+        return true;
     }
 
     @Override
@@ -126,10 +131,8 @@ public class DateSelector implements Outputable {
         return "DateSelector [names=" + Arrays.toString(names) + ", day=" + day + ", month=" + month + ", year=" + year + "]";
     }
 
-    public java.sql.Date getDate() {
-        Calendar gc = GregorianCalendar.getInstance();
-        gc.set(year, month - 1, day);
-        return new java.sql.Date(gc.getTime().getTime());
+    public DayDate getDate() {
+        return CalendarUtil.getDateFromComponents(year, month, day);
     }
 
     public static SimpleDateFormat getDateFormat() {