roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r326197 - /incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java
Date Tue, 18 Oct 2005 18:34:41 GMT
Author: agilliland
Date: Tue Oct 18 11:34:36 2005
New Revision: 326197

URL: http://svn.apache.org/viewcvs?rev=326197&view=rev
Log:
fixing pubtime conversions to handle various timezones better.


Modified:
    incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java

Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java?rev=326197&r1=326196&r2=326197&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java
(original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/weblog/formbeans/WeblogEntryFormEx.java
Tue Oct 18 11:34:36 2005
@@ -2,9 +2,11 @@
 
 import java.sql.Timestamp;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.TimeZone;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,6 +29,7 @@
 import org.roller.presentation.forms.WeblogEntryForm;
 import org.roller.util.DateUtil;
 
+
 /**
  * Extends the WeblogEntryForm so that additional properties may be added.
  * @struts.form name="weblogEntryFormEx"
@@ -99,28 +102,28 @@
         
         super.copyTo(entry, locale);
         
-        // First parts the date string from the calendar 
-        final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
-        Date newDate = null;
-        try
-        {
-            if(getDateString() != null && !"0/0/0".equals(getDateString()))
-                newDate = df.parse(getDateString());
-        }
-        catch (ParseException e)
-        {
-            throw new RollerException("ERROR parsing date.");
-        }
-        
-        // Now handle the time from the hour, minute and second combos
-        if(newDate != null) {
-            final Calendar cal = Calendar.getInstance(locale);
-            cal.setTime(newDate);
-            cal.setTimeZone(entry.getWebsite().getTimeZoneInstance());
-            cal.set(Calendar.HOUR_OF_DAY, getHours().intValue());
-            cal.set(Calendar.MINUTE, getMinutes().intValue());
-            cal.set(Calendar.SECOND, getSeconds().intValue());
-            entry.setPubTime(new Timestamp(cal.getTimeInMillis()));
+        // calculate date for pubtime
+        if(getDateString() != null && !"0/0/0".equals(getDateString())) {
+            Date pubtime = null;
+            
+            TimeZone timezone = entry.getWebsite().getTimeZoneInstance();
+            try {
+                // gather submitted pubtime in a string
+                String time = getHours()+":"+getMinutes()+":"+getSeconds();
+                String datetime = getDateString()+" "+time;
+                mLogger.debug("datetime = "+datetime);
+                
+                // now parse pubtime in a timezone sensitive manner
+                SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
+                sdf.setTimeZone(timezone);
+                pubtime = sdf.parse(datetime);
+                entry.setPubTime(new Timestamp(pubtime.getTime()));
+                
+            } catch(Exception e) {
+                mLogger.error(e);
+            }
+
+            mLogger.debug("set pubtime to "+entry.getPubTime());
         }
         
         entry.setPlugins( StringUtils.join(this.pluginsArray,",") );
@@ -235,6 +238,7 @@
             
             DateFormat df = DateFormat.getDateInstance(
                     DateFormat.SHORT, locale);
+            df.setTimeZone(website.getTimeZoneInstance());
             mDateString = df.format(getPubTime());
             
         } else {



Mime
View raw message