Aktivitäten

April 11
Dave Kliczbor kommentierte LPS-29395.
07:50 Yeah, well, after waiting HALF A YEAR for any reaction, you only give me 10 days for answering before closing it ... something is very wrong here. I thought you guys set up this ticket system for a reason??? Okay, it would've been smart of me to find and click the "watch" button, but it would've been way smarter to automatically put the reporter onto the watch list for "his" issues... So, I haven't tested whether this works on 6.2.0, but the code of DateUtil.getDaysBetween() has not changed. Therefore, this issue is not fixed. Here's my test class to test it separately from Liferay on the command line -- but be warned: getFixedDaysBetween() may work here and now, but inside Liferay, it may not. It may work for you now, but after changing back from Daylight Savings Time to Standard Time, it may not work anymore. Or the other way round. Or this issue only comes up in timezones in the east of GMT, but only during Daylight Savings time. It may be a completely different issue (maybe a misconfiguration on tomcat or whatever). I don't know. I'm fed up with this issue. {code:java} import java.text.DateFormat; import java.text.SimpleDateFormat; import java.text.Format; import java.text.ParseException; import java.util.Vector; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; public class DateUtil { public static final String ISO_8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ"; private static long _getTimeInMillis(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DATE); int hour = 0; int minute = 0; int second = 0; cal.set(year, month, day, hour, minute, second); long millis = cal.getTimeInMillis() / (1000*60*60*24); return millis; } public static boolean beforeByDay(Date date1, Date date2) { long millis1 = _getTimeInMillis(date1); long millis2 = _getTimeInMillis(date2); if (millis1 < millis2) { return true; } else { return false; } } public static int getDaysBetween(Date date1, Date date2) { return getDaysBetween(date1, date2, null); } public static int getDaysBetween( Date date1, Date date2, TimeZone timeZone) { if (date1.after(date2)) { Date tempDate = date1; date1 = date2; date2 = tempDate; } Calendar startCal = null; Calendar endCal = null; int offset = 0; if (timeZone == null) { startCal = new GregorianCalendar(); endCal = new GregorianCalendar(); } else { startCal = new GregorianCalendar(timeZone); endCal = new GregorianCalendar(timeZone); offset = timeZone.getRawOffset(); } startCal.setTime(date1); startCal.add(Calendar.MILLISECOND, offset); endCal.setTime(date2); endCal.add(Calendar.MILLISECOND, offset); int daysBetween = 0; while (beforeByDay(startCal.getTime(), endCal.getTime())) { startCal.add(Calendar.DAY_OF_MONTH, 1); daysBetween++; } return daysBetween; } public static Date newDate() { return new Date(); } public static Date newDate(long date) { return new Date(date); } public static long newTime() { Date date = new Date(); return date.getTime(); } public static Date parseDate(String dateString, Locale locale) throws ParseException { DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale); return dateFormat.parse(dateString); } public static int getFixedDaysBetween(Date date1, Date date2, TimeZone timeZone) { if (date1.after(date2)) { Date tempDate = date1; date1 = date2; date2 = tempDate; } Calendar startCal = null; Calendar endCal = null; int offset = 0; if (timeZone == null) { startCal = new GregorianCalendar(); endCal = new GregorianCalendar(); } else { startCal = new GregorianCalendar(timeZone); endCal = new GregorianCalendar(timeZone); } startCal.setTime(date1); endCal.setTime(date2); int daysBetween = 0; while (beforeByDay(startCal.getTime(), endCal.getTime())) { startCal.add(Calendar.DAY_OF_MONTH, 1); daysBetween++; } return daysBetween; } public static void main(String[] args) { TimeZone tz = TimeZone.getTimeZone("Europe/Berlin"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm zzz"); String[] ds = new String[]{ "2013-03-13 14:06 MET", "2013-03-12 22:59 MET", "2013-03-12 18:04 MET", "2012-03-28 03:30 MET", "2012-03-28 02:30 MET", "2012-03-28 01:30 MET", "2012-03-28 00:30 MET", "2012-03-27 23:30 MET", "2012-03-27 22:30 MET", }; Vector<Date> dv = new Vector<Date>( ); for( String s: ds ) { try { dv.add(df.parse(s)); } catch(java.text.ParseException e) { System.out.println(e.getMessage()); } } System.out.println("=================================================="); Date od = null; for( Date d: dv ) { if( od != null ) System.out.println(getDaysBetween(d, od, tz) + " " + getFixedDaysBetween(d, od, tz)); System.out.println(d); od = d; } System.out.println("=================================================="); Date cd = new Date(); for( Date d: dv ) { System.out.println(d + " " + getDaysBetween(d, cd, tz) + " " + getFixedDaysBetween(d, cd, tz)); } System.out.println("=================================================="); int daysBetween = -1; for( Date d: dv ) { int curDaysBetween = getDaysBetween(d, new Date(), tz); if( curDaysBetween > daysBetween ) { daysBetween = curDaysBetween; if( curDaysBetween == 0 ) System.out.println("---- Heute"); else if( curDaysBetween == 1 ) System.out.println("---- Gestern"); else System.out.println("---- Vor " + curDaysBetween + " Tagen"); } System.out.println(d); } System.out.println("=================================================="); daysBetween = -1; for( Date d: dv ) { int curDaysBetween = getFixedDaysBetween(d, new Date(), tz); if( curDaysBetween > daysBetween ) { daysBetween = curDaysBetween; if( curDaysBetween == 0 ) System.out.println("---- Heute"); else if( curDaysBetween == 1 ) System.out.println("---- Gestern"); else System.out.println("---- Vor " + curDaysBetween + " Tagen"); } System.out.println(d); } System.out.println("=================================================="); } } {code}
März 15
Laura Liparulo und Dave Kliczbor sind nun Freunde.
10:19
Januar 24
Dave Kliczbor kommentierte LPS-29395.
November 29
Vishal Panchal hat auf die Nachricht von Dave Kliczbor im Forum geantwortet, in Liferay.com.
Oktober 30
Dave Kliczbor und Nikolai Reisch sind nun Freunde.
04:41
September 11
Dave Kliczbor und Frank Pientka sind nun Freunde.
05:28
August 30
Dave Kliczbor hat neue Wiki Seite, How to make a minimized Liferay 6.1.1 GA2 barebone installation for project startup in Dave Kliczbor angelegt.
09:17
Dave Kliczbor kommentierte LPS-20237.
August 29
Dave Kliczbor und Olaf Kock sind nun Freunde.
00:19
Dave Kliczbor kommentierte LPS-29395.
Die Aktivitäten von Dave Kliczbor abonnieren. (Öffnet neues Fenster)