Bug 1239823 - Part 1: Parse min/max date before use r=margaret draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 03 Feb 2016 15:17:38 -0800
changeset 330181 237b6738ff4323b4adc81926759d9118725507d6
parent 330180 86eab7abbd7db485e86cbc7424a01aaef0a7beb8
child 330182 8a9182bb3337fea8720dc6a08afa325333e50c7d
push id10701
push userahunt@mozilla.com
push dateWed, 10 Feb 2016 22:45:06 +0000
reviewersmargaret
bugs1239823
milestone47.0a1
Bug 1239823 - Part 1: Parse min/max date before use r=margaret MozReview-Commit-ID: 4th3CJwwcDg
mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DateTimePicker.java
@@ -264,16 +264,51 @@ public class DateTimePicker extends Fram
         display.getMetrics(dm);
         mScreenWidth = display.getWidth() / dm.densityDpi;
         mScreenHeight = display.getHeight() / dm.densityDpi;
 
         if (DEBUG) {
             Log.d(LOGTAG, "screen width: " + mScreenWidth + " screen height: " + mScreenHeight);
         }
 
+        // Set the min / max attribute.
+        try {
+            if (minDateValue != null && !minDateValue.equals("")) {
+                mMinDate.setTime(new SimpleDateFormat(dateFormat).parse(minDateValue));
+            } else {
+                mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
+            }
+        } catch (Exception ex) {
+            Log.e(LOGTAG, "Error parsing format sting: " + ex);
+            mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
+        }
+
+        try {
+            if (maxDateValue != null && !maxDateValue.equals("")) {
+                mMaxDate.setTime(new SimpleDateFormat(dateFormat).parse(maxDateValue));
+            } else {
+                mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
+            }
+        } catch (Exception ex) {
+            Log.e(LOGTAG, "Error parsing format string: " + ex);
+            mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
+        }
+
+        // Find the initial date from the constructor arguments.
+        try {
+            if (!dateTimeValue.equals("")) {
+                mTempDate.setTime(new SimpleDateFormat(dateFormat).parse(dateTimeValue));
+            } else {
+                mTempDate.setTimeInMillis(System.currentTimeMillis());
+            }
+        } catch (Exception ex) {
+            Log.e(LOGTAG, "Error parsing format string: " + ex);
+            mTempDate.setTimeInMillis(System.currentTimeMillis());
+        }
+
         // If we're displaying a date, the screen is wide enough
         // (and if we're using an SDK where the calendar view exists)
         // then display a calendar.
         if (Versions.feature11Plus &&
             (mState == PickersState.DATE || mState == PickersState.DATETIME) &&
             mScreenWidth >= SCREEN_SIZE_THRESHOLD) {
 
             if (DEBUG) {
@@ -307,51 +342,16 @@ public class DateTimePicker extends Fram
             // time spinners, and if there is no calendar displayed, we should
             // display the fields in one row.
             if (mScreenWidth > mScreenHeight && mState == PickersState.DATETIME) {
                 mPickers.setOrientation(LinearLayout.HORIZONTAL);
             }
             mCalendar = null;
         }
 
-        // Find the initial date from the constructor arguments.
-        try {
-            if (!dateTimeValue.equals("")) {
-                mTempDate.setTime(new SimpleDateFormat(dateFormat).parse(dateTimeValue));
-            } else {
-                mTempDate.setTimeInMillis(System.currentTimeMillis());
-            }
-        } catch (Exception ex) {
-            Log.e(LOGTAG, "Error parsing format string: " + ex);
-            mTempDate.setTimeInMillis(System.currentTimeMillis());
-        }
-
-	// Set the min / max attribute.
-	try {
-	    if (minDateValue != null && !minDateValue.equals("")) {
-		mMinDate.setTime(new SimpleDateFormat(dateFormat).parse(minDateValue));
-	    } else {
-		mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
-	    }
-	} catch (Exception ex) {
-	    Log.e(LOGTAG, "Error parsing format sting: " + ex);
-	    mMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
-	}
-
-	try {
-	    if (maxDateValue != null && !maxDateValue.equals("")) {
-		mMaxDate.setTime(new SimpleDateFormat(dateFormat).parse(maxDateValue));
-	    } else {
-		mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
-	    }
-	} catch (Exception ex) {
-	    Log.e(LOGTAG, "Error parsing format string: " + ex);
-	    mMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
-	}
-
         // Initialize all spinners.
         mDaySpinner = setupSpinner(R.id.day, 1,
                                    mTempDate.get(Calendar.DAY_OF_MONTH));
         mDaySpinner.setFormatter(TWO_DIGIT_FORMATTER);
         mDaySpinnerInput = (EditText) mDaySpinner.getChildAt(1);
 
         mMonthSpinner = setupSpinner(R.id.month, 1,
                                      mTempDate.get(Calendar.MONTH) + 1); // Month is 0-based