diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-08-22 11:13:29 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-08-22 11:13:29 +0000 |
commit | cc991dafd46f0ad3a730ee8192fd650e4ea26b3e (patch) | |
tree | 5731c145bc3512e4c6c3872a30515b9c78292131 /src | |
parent | ea8219f86a5e085e3c27852e70a883eab21ad995 (diff) | |
download | vaadin-framework-cc991dafd46f0ad3a730ee8192fd650e4ea26b3e.tar.gz vaadin-framework-cc991dafd46f0ad3a730ee8192fd650e4ea26b3e.zip |
#6066 Support for time zones in DateField
svn changeset:20536/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/ui/DateField.java | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java index eee26555f7..1ecf616832 100644 --- a/src/com/vaadin/ui/DateField.java +++ b/src/com/vaadin/ui/DateField.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.Date; import java.util.Locale; import java.util.Map; +import java.util.TimeZone; import com.vaadin.data.Property; import com.vaadin.data.Validator; @@ -126,6 +127,8 @@ public class DateField extends AbstractField implements private String defaultParseErrorMessage = "Date format not recognized"; + private TimeZone timeZone = null; + /* Constructors */ /** @@ -290,7 +293,7 @@ public class DateField extends AbstractField implements || variables.containsKey("min") || variables.containsKey("sec") || variables.containsKey("msec") || variables - .containsKey("dateString"))) { + .containsKey("dateString"))) { // Old and new dates final Date oldDate = (Date) getValue(); @@ -511,6 +514,10 @@ public class DateField extends AbstractField implements // Try to parse the given string value to Date try { final SimpleDateFormat parser = new SimpleDateFormat(); + final TimeZone currentTimeZone = getTimeZone(); + if (currentTimeZone != null) { + parser.setTimeZone(currentTimeZone); + } final Date val = parser.parse(newValue.toString()); super.setValue(val, repaintIsNotNeeded); } catch (final ParseException e) { @@ -635,6 +642,11 @@ public class DateField extends AbstractField implements newCal.setTime(currentDate); } + final TimeZone currentTimeZone = getTimeZone(); + if (currentTimeZone != null) { + newCal.setTimeZone(currentTimeZone); + } + return newCal; } @@ -791,6 +803,37 @@ public class DateField extends AbstractField implements defaultParseErrorMessage = parsingErrorMessage; } + /** + * Sets the time zone used by this date field. The time zone is used to + * convert the absolute time in a Date object to a logical time displayed in + * the selector and to convert the select time back to a Date object. + * + * If no time zone has been set, the current default time zone returned by + * {@code TimeZone.getDefault()} is used. + * + * @see #getTimeZone() + * @param timeZone + * the time zone to use for time calculations. + */ + public void setTimeZone(TimeZone timeZone) { + this.timeZone = timeZone; + requestRepaint(); + } + + /** + * Gets the time zone used by this field. The time zone is used to convert + * the absolute time in a Date object to a logical time displayed in the + * selector and to convert the select time back to a Date object. + * + * If {@code null} is returned, the current default time zone returned by + * {@code TimeZone.getDefault()} is used. + * + * @return the current time zone + */ + public TimeZone getTimeZone() { + return timeZone; + } + public static class UnparsableDateString extends Validator.InvalidValueException { |