I was trying to use the datetime.DateTextField and it was giving me a little
grief when I was trying to use DateTime objects with it. It was my
understanding that that datetime project was to be built around the joda
package. Here is a patch the removes the java.util.Date "stuff" in an
attempt to be a pure DateTime converter.
With the following patch in place, my code works properly (ie, no errors
parsing or returning dates). Let me know if I'm on the wrong track here,
please.
Chuck
Index:
Q:/wicket/SNAPSHOT/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java
===================================================================
---
Q:/wicket/SNAPSHOT/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java
(revision 507915)
+++
Q:/wicket/SNAPSHOT/wicket-datetime/src/main/java/wicket/datetime/util/DateConverter.java
(working copy)
@@ -16,9 +16,6 @@
*/
package wicket.datetime.util;
-import java.util.Date;
-import java.util.TimeZone;
-
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.MutableDateTime;
@@ -99,21 +96,21 @@
DateTimeFormatter format = getFormat();
if (applyTimeZoneDifference) {
- TimeZone zone = getClientTimeZone();
+ DateTimeZone zone = getClientTimeZone();
// instantiate now/ current time
MutableDateTime dt = new MutableDateTime();
if (zone != null) {
// set time zone for client
- format =
format.withZone(DateTimeZone.forTimeZone(zone));
- dt.setZone(DateTimeZone.forTimeZone(zone));
+ format = format.withZone(zone);
+ dt.setZone(zone);
}
// parse date retaining the time of the submission
format.parseInto(dt, value, 0);
// apply the server time zone to the parsed value
dt.setZone(getTimeZone());
- return dt.toDate();
+ return dt;
} else {
- return format.parseDateTime(value).toDate();
+ return format.parseDateTime(value);
}
}
@@ -122,14 +119,14 @@
*/
public final String toString(Object value) {
- DateTime dt = new DateTime(((Date) value).getTime(),
getTimeZone());
+ DateTime dt = new DateTime(value, getTimeZone());
DateTimeFormatter format = getFormat();
if (applyTimeZoneDifference) {
- TimeZone zone = getClientTimeZone();
+ DateTimeZone zone = getClientTimeZone();
if (zone != null) {
// apply time zone to formatter
- format =
format.withZone(DateTimeZone.forTimeZone(zone));
+ format = format.withZone(zone);
}
}
return format.print(dt);
@@ -140,10 +137,13 @@
*
* @return The client's time zone or null
*/
- protected TimeZone getClientTimeZone() {
+ protected DateTimeZone getClientTimeZone() {
ClientInfo info = Session.get().getClientInfo();
if (info instanceof WebClientInfo) {
- return ((WebClientInfo)
info).getProperties().getTimeZone();
+ java.util.TimeZone zone = ((WebClientInfo)
info).getProperties().getTimeZone();
+ if (zone != null) {
+ return DateTimeZone.forTimeZone(zone);
+ }
}
return null;
}
--
View this message in context:
http://www.nabble.com/-datetime--DateConverter-tf3233793.html#a8985478
Sent from the Wicket - User mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user