Author: jflesch
Date: 2007-08-13 16:42:45 +0000 (Mon, 13 Aug 2007)
New Revision: 14652

Modified:
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
Log:
Try to instanciate a little bit less of SimpleDateFormat + Fix the use of GMT 
time (really this time)

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java  2007-08-13 
16:25:07 UTC (rev 14651)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/DraftPanel.java  2007-08-13 
16:42:45 UTC (rev 14652)
@@ -48,9 +48,19 @@

        private JDialog dialog;

+       private final SimpleDateFormat gmtConverter;
+       private final SimpleDateFormat dateParser;
+       private final SimpleDateFormat messageDateFormat;
+
+
        public DraftPanel(MiniFrostPanel mainPanel) {
                this.mainPanel = mainPanel;

+               gmtConverter = new SimpleDateFormat("yyyy.M.d HH:mm:ss");
+               gmtConverter.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
+               dateParser = new SimpleDateFormat("yyyy.M.d HH:mm:ss");
+               messageDateFormat = new SimpleDateFormat("yyyy.MM.dd - 
HH:mm:ss");
+
                panel = new JPanel(new BorderLayout(5, 5));

                Vector ids = new Vector();
@@ -169,18 +179,12 @@
        }


-       public static Date getGMTDate() {
+       public Date getGMTDate() {
                /* dirty way to obtain the GMT date */
+               String dateStr = gmtConverter.format(new Date());

-               SimpleDateFormat gmtFormat = new SimpleDateFormat("yyyy.M.d 
HH:mm:ss");
-               gmtFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
-
-               String dateStr = gmtFormat.format(new Date());
-
-               SimpleDateFormat finalDate = new SimpleDateFormat("yyyy.M.d 
HH:mm:ss");
-
                try {
-                       return finalDate.parse(dateStr);
+                       return dateParser.parse(dateStr);
                } catch(java.text.ParseException e) {
                        Logger.warning(null, "DraftPanel : Can't get the GMT 
date => will use the local time");
                        return new Date();
@@ -236,8 +240,7 @@
                } else if (e.getSource() == sendButton) {
                        fillInDraft();

-                       Date date = new Date();
-                       SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy.MM.dd - HH:mm:ss");
+                       Date date = getGMTDate();

                        /* text */

@@ -245,14 +248,14 @@

                        txt = txt.replaceAll("\\$sender\\$", 
authorBox.getSelectedItem().toString());

-                       String dateStr = dateFormat.format(date).toString();
+                       String dateStr = 
messageDateFormat.format(date).toString();
                        txt = txt.replaceAll("\\$dateAndTime\\$", dateStr);

                        draft.setText(txt);


                        /* date */
-                       draft.setDate(getGMTDate());
+                       draft.setDate(date);


                        /* POST */

Modified: 
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java   
2007-08-13 16:25:07 UTC (rev 14651)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java   
2007-08-13 16:42:45 UTC (rev 14652)
@@ -33,8 +33,12 @@
  */
 public class KSKMessageParser {

+       private final static SimpleDateFormat simpleFormat = new 
SimpleDateFormat("yyyy.M.d HH:mm:ss");
+       private SimpleDateFormat gmtFormat;
+
        public KSKMessageParser() {
-
+               gmtFormat = new SimpleDateFormat("yyyy.M.d HH:mm:ss");
+               gmtFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
        }

        private String messageId;
@@ -73,17 +77,14 @@
                                String publicKey,
                                Vector attachments,
                                Identity identity) {
+               this();

-               SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.M.d 
HH:mm:ss");
-               // the date is already GMT-ized
-               //dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
-
                this.messageId = ""; /* will be generated from the SHA1 of the 
content */
                this.inReplyTo = inReplyTo;
                this.from = from;
                this.subject = subject;

-               String[] date = dateFormat.format(dateUtil).toString().split(" 
");
+               String[] date = 
simpleFormat.format(dateUtil).toString().split(" ");
                this.date = date[0];
                this.time = date[1];

@@ -163,15 +164,20 @@
                        read = true;
                }

-               SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.M.d 
HH:mm:ss");
-
                date = date.trim();
                time = time.trim();

                date += " "+time;

-               java.util.Date dateUtil = dateFormat.parse(date, new 
java.text.ParsePosition(0));
+               java.util.Date dateUtil = null;

+               try {
+                       dateUtil = simpleFormat.parse(date);
+               } catch(java.text.ParseException e) {
+                       Logger.notice(this, "Can't parse the date !");
+                       return false;
+               }
+
                if (dateUtil != null) {
                        long dateDiff = 
KSKBoard.getMidnight(dateUtil).getTime() - 
KSKBoard.getMidnight(boardDate).getTime();
                        /* we accept between X days before and X days after */
@@ -489,14 +495,11 @@
                 */
                /* (I'm still thinking that mixing up Boards & private messages 
is a BAD idea) */

-               SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.M.d 
HH:mm:ss");
-               dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
-
                inReplyTo = null;
                from = 
"["+I18n.getMessage("thaw.plugin.miniFrost.encrypted")+"]";
                subject = 
"["+I18n.getMessage("thaw.plugin.miniFrost.encryptedBody").replaceAll("X", 
recipient)+"]";

-               String[] date = dateFormat.format(new 
Date()).toString().split(" ");
+               String[] date = gmtFormat.format(new Date()).toString().split(" 
");
                this.date = date[0];
                this.time = date[1];



Reply via email to