diff options
Diffstat (limited to 'src/java/com')
-rw-r--r-- | src/java/com/juick/http/www/PageTemplates.java | 49 | ||||
-rw-r--r-- | src/java/com/juick/http/www/UserThread.java | 2 |
2 files changed, 29 insertions, 22 deletions
diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 23f2b007..32e77239 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -43,7 +43,7 @@ import ru.sape.Sape; public class PageTemplates { public static Sape sape = null; - private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); private static SimpleDateFormat sdfJS = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss"); @@ -289,33 +289,40 @@ public class PageTemplates { } return days + " " + unit + " назад"; } else { - try { - Date pDate = sdfSQL.parse(fulldate); - Calendar c = Calendar.getInstance(); - int curyear = c.get(Calendar.YEAR); - c.setTime(pDate); - if (c.get(Calendar.YEAR) == curyear) { - return sdfSimple.format(pDate); - } else { - return sdfFull.format(pDate); + String ret = fulldate; + synchronized (sdfSQL) { + try { + Date pDate = sdfSQL.parse(fulldate); + Calendar c = Calendar.getInstance(); + int curyear = c.get(Calendar.YEAR); + c.setTime(pDate); + if (c.get(Calendar.YEAR) == curyear) { + ret = sdfSimple.format(pDate); + } else { + ret = sdfFull.format(pDate); + } + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + fulldate); } - } catch (Exception e) { - return fulldate; } + return ret; } } public static String formatJSLocalTime(String ts) { - try { - Date date = sdfSQL.parse(ts); - return "<script type=\"text/javascript\">" - + "var d=new Date(" + date.getTime() + ");" - + "document.write((d.getDate()<10?'0':'')+d.getDate()+'.'+(d.getMonth()<9?'0':'')+(d.getMonth()+1)+'.'+d.getFullYear()+' '+(d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes());" - + "</script>"; - } catch (Exception e) { - System.err.print(e); + String ret = ""; + synchronized (sdfSQL) { + try { + Date date = sdfSQL.parse(ts); + ret = "<script type=\"text/javascript\">" + + "var d=new Date(" + date.getTime() + ");" + + "document.write((d.getDate()<10?'0':'')+d.getDate()+'.'+(d.getMonth()<9?'0':'')+(d.getMonth()+1)+'.'+d.getFullYear()+' '+(d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes());" + + "</script>"; + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + ts); + } } - return ""; + return ret; } public static String formatReplies(int replies) { diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index 57c1a696..3357f65c 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -293,7 +293,7 @@ public class UserThread { int childs = msg.getChildsCount(); if (ReplyTo == 0 && childs > 1 && replies.size() > 10) { - out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.RID + ")\">" + PageTemplates.formatReplies(childs) + " more</a></div>"); + out.println(" <div class=\"msg-comments\"><a href=\"#\" onclick=\"return showMoreReplies(" + msg.RID + ")\">" + PageTemplates.formatReplies(childs) + "</a></div>"); } out.println(" </div>"); |