package tigase.muc;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {

	private final static SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

	public static String formatDatetime(Date date) {
		Date d = new Date(date.getTime());
		return FORMAT.format(d);
	}

	/**
	 * Used only in jabber:x:delivery
	 * 
	 * @param date
	 * @return
	 */
	public static String formatOld(final Date date) {
		Calendar now = Calendar.getInstance();
		now.setTimeZone(TimeZone.getTimeZone("GMT"));
		now.setTime(date);
		return String.format("%1$tY%1$tm%1$tdT%1$tH:%1$tM:%1$tS", now);
	}

	public static Date parse(String s) {
		try {
			return FORMAT.parse(s);
		} catch (Exception e) {
			return null;
		}
	}

	{
		FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
	}

	private DateUtil() {
	}
}

@@ -307,40 +307,113 @@
 %7B%0A%09%09
-Date d = new Date(date.getTime()
+Calendar now = Calendar.getInstance();%0A%09%09now.setTimeZone(TimeZone.getTimeZone(%22GMT%22));%0A%09%09now.setTime(date
 );%0A%09
@@ -424,22 +424,22 @@
 urn 
-FORMAT
+String
 .format(
 d);%0A
@@ -434,17 +434,59 @@
 .format(
-d
+%22%251$tY-%251$tm-%251$tdT%251$tH:%251$tM:%251$tSZ%22, now
 );%0A%09%7D%0A%0A%09

fix date parsing