### Eclipse Workspace Patch 1.0 #P org.eclipse.team.cvs.ui Index: src/org/eclipse/team/internal/ccvs/ui/CVSHistoryTableProvider.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSHistoryTableProvider.java,v retrieving revision 1.17 diff -u -r1.17 CVSHistoryTableProvider.java --- src/org/eclipse/team/internal/ccvs/ui/CVSHistoryTableProvider.java 27 Apr 2006 22:45:27 -0000 1.17 +++ src/org/eclipse/team/internal/ccvs/ui/CVSHistoryTableProvider.java 21 Jun 2006 09:39:52 -0000 @@ -77,6 +77,8 @@ ThemeListener themeListener; + final DateFormat fDateFormat= new RelativeDateFormat(); + public HistoryLabelProvider(CVSHistoryTableProvider provider){ PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(themeListener= new ThemeListener(provider)); } @@ -167,7 +169,7 @@ case COL_DATE : long date = entry.getTimestamp(); Date dateFromLong = new Date(date); - return DateFormat.getInstance().format(dateFromLong); + return fDateFormat.format(dateFromLong); case COL_AUTHOR : return entry.getAuthor(); case COL_COMMENT : Index: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormat.java =================================================================== RCS file: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormat.java diff -N src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormat.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormat.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.ui; + +import java.text.*; +import java.util.Date; + +import org.eclipse.core.runtime.Assert; + +import com.ibm.icu.text.DateFormat; +import com.ibm.icu.text.MessageFormat; +import com.ibm.icu.util.Calendar; + +/** + * Formats dates depending on their age relative to the current time. Only relevant date fields are + * displayed (e.g. no day or date indication for dates on the same day, no year indication for dates + * in the current year). Recent dates are reported relatively to the current time similarly to the + * following scheme for an English locale: + *
+ * The time segments may either be discrete or sliding: the current year or month, yesterday and + * today are discrete time windows that change when the current time moves over a time border (e.g. + * midnight). The last minutes are a sliding window that trails the current time. + *
+ *+ * Current restrictions: + *
+ *+ * Example: if the current date is on a Thursday, then the most recent Friday would be within + * the last week, but neither of the two most recent Tuesdays. + *
+ */ + private static final int LAST_WEEK= -4; + + private final Format fOldFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_oldFormat); + private final Format fSameYearFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_sameYearFormat); + private final Format fSameMonthFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_sameMonthFormat); + private final Format fLastWeekFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_lastWeekFormat); + private final Format fSameWeekFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_sameWeekFormat); + private final Format fYesterdayFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_yesterdayFormat); + private final Format fSameDayFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_sameDayFormat); + private final Format fSameHourFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_recentMinutesFormat); + private final Format fSameMinuteFormat= new MessageFormat(RelativeDateFormatMessages.RelativeDateFormat_sameMinuteFormat); + + /** Maximum number of minutes to report age instead of timestamp. */ + private final int fSmallPeriod; + + /** + * Creates a new relative date format. + * + * @param relativeMinutes the number of minutes to format as relative age ("n minutes ago"), set + * to a negative value to disable relative formats. + */ + public RelativeDateFormat(int relativeMinutes) { + fSmallPeriod= -relativeMinutes; + DateFormat format= DateFormat.getDateTimeInstance(); + calendar= format.getCalendar(); + numberFormat= format.getNumberFormat(); + } + + /** + * Creates a new relative date format. Equivalent to + * {@link #RelativeDateFormat(int) RelativeDateFormat(30)}. + */ + public RelativeDateFormat() { + this(30); + } + + /* (non-Javadoc) + * @see com.ibm.icu.text.DateFormat#format(com.ibm.icu.util.Calendar, java.lang.StringBuffer, java.text.FieldPosition) + */ + public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition fieldPosition) { + Calendar now= (Calendar) cal.clone(); + now.setTimeInMillis(System.currentTimeMillis()); + + int field= getDiscriminatingField(cal, now); + Date date= cal.getTime(); + Format format= getFormat(field, date, now.getTime()); + + return format.format(new Object[] { date }, toAppendTo, fieldPosition); + } + + private int getDiscriminatingField(Calendar then, Calendar now) { + // check for relative sliding windows + Calendar temp= (Calendar) now.clone(); + temp.add(Calendar.MINUTE, -2); + if (temp.before(then)) + return LAST_MINUTE; + temp.setTime(now.getTime()); + temp.add(Calendar.MINUTE, fSmallPeriod); + if (temp.before(then)) + return LAST_SMALL_PERIOD; + + // check for relative periods overlapping larger ones (yesterday may be last year, last week + // may be last month) + Calendar midnight= (Calendar) now.clone(); + midnight.set(Calendar.HOUR_OF_DAY, temp.getMinimum(Calendar.HOUR_OF_DAY)); + midnight.set(Calendar.MINUTE, temp.getMinimum(Calendar.MINUTE)); + midnight.set(Calendar.SECOND, temp.getMinimum(Calendar.SECOND)); + midnight.set(Calendar.MILLISECOND, temp.getMinimum(Calendar.MILLISECOND)); + + // yesterday + temp.setTime(then.getTime()); + temp.add(Calendar.DATE, 1); + if (temp.after(midnight) && temp.get(Calendar.DATE) == now.get(Calendar.DATE)) + return YESTERDAY; + + // last week is from one week before now to discrete week end + midnight.add(Calendar.DATE, 1); + temp.setTime(then.getTime()); + temp.add(Calendar.WEEK_OF_MONTH, 1); + if (temp.after(midnight) && temp.get(Calendar.WEEK_OF_YEAR) == now.get(Calendar.WEEK_OF_YEAR)) + return LAST_WEEK; + + // check for discrete periods + int[] fields= { Calendar.YEAR, Calendar.MONTH, Calendar.WEEK_OF_MONTH, Calendar.DAY_OF_WEEK, Calendar.HOUR_OF_DAY }; + for (int i= 0; i < fields.length; i++) { + int field= fields[i]; + if (now.get(field) != then.get(field)) + return field; + } + + return Calendar.HOUR_OF_DAY; + } + + /** + * Returns the proper format given the discriminatingfield
and changes
+ * date
to be relative if the format is a relative one.
+ *
+ * @param field the discriminating field
+ * @param date the date that will be formatted, may be modified
+ * @param now the reference date
+ * @return a format that can format date
+ */
+ private Format getFormat(int field, Date date, Date now) {
+ switch (field) {
+ case Calendar.YEAR:
+ return fOldFormat;
+ case Calendar.MONTH:
+ return fSameYearFormat;
+ case Calendar.WEEK_OF_MONTH:
+ return fSameMonthFormat;
+ case LAST_WEEK:
+ return fLastWeekFormat;
+ case Calendar.DAY_OF_WEEK:
+ return fSameWeekFormat;
+ case YESTERDAY:
+ return fYesterdayFormat;
+ case Calendar.HOUR_OF_DAY:
+ return fSameDayFormat;
+ case LAST_SMALL_PERIOD:
+ long delta= now.getTime() - date.getTime();
+ date.setTime(delta);
+ return fSameHourFormat;
+ case LAST_MINUTE:
+ delta= now.getTime() - date.getTime();
+ date.setTime(delta);
+ return fSameMinuteFormat;
+ default:
+ Assert.isTrue(false);
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.text.DateFormat#parse(java.lang.String, com.ibm.icu.util.Calendar, java.text.ParsePosition)
+ */
+ public void parse(String text, Calendar cal, ParsePosition pos) {
+ throw new UnsupportedOperationException();
+ }
+}
Index: .settings/org.eclipse.core.resources.prefs
===================================================================
RCS file: .settings/org.eclipse.core.resources.prefs
diff -N .settings/org.eclipse.core.resources.prefs
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ .settings/org.eclipse.core.resources.prefs 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,3 @@
+#Tue Jun 20 17:31:53 CEST 2006
+eclipse.preferences.version=1
+encoding//src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.properties=8859_1
Index: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.properties
===================================================================
RCS file: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.properties
diff -N src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.properties 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,46 @@
+###############################################################################
+# Copyright (c) 2006 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+# In all time formats, there is one date argument ({0}) that is formatted in some
+# user friendly way. All formats are MessageFormat patterns. The result should best
+# answer the question "When did the event occur?", which may be answered by giving the
+# elapsed time since the event ("3 minutes ago") under some circumstances, or by giving
+# a partial description ("July 13"). Also, the amount of information should be kept
+# minimal (e.g., the time of day is not interesting for events that occurred a long
+# time ago).
+
+# The following two formats will be fed not with the absolute date, but with the age
+# of the date compared to the current.
+
+# format for dates in the last minute
+RelativeDateFormat_sameMinuteFormat=1 minute ago
+# format for dates in the most recent couple of minutes (may say how old the date is in minutes)
+RelativeDateFormat_recentMinutesFormat={0,time,m} minutes ago
+
+# In the following formats, when the time of day is included. It should be similar to the
+# result of DateFormat.getTimeInstance(SHORT).
+
+# format for dates on the same day (should be similar to result of DateFormat.getTimeInstance(SHORT))
+RelativeDateFormat_sameDayFormat={0,time,short}
+# format for yesterday dates (should be similar to sameWeekFormat, but may replace the weekday with a term for 'Yesterday')
+RelativeDateFormat_yesterdayFormat=Yesterday, {0,time,short}
+# format for dates in the same week (similar to sameDayFormat, could include the weekday, should include the time of day)
+RelativeDateFormat_sameWeekFormat={0,time,EEEE}, {0,time,short}
+# format for dates in last week (should be similar to sameWeekFormat, but may indicate that the date is in the previous week)
+# Note: the same weekday will only appear either formatted as sameWeek or lastWeek, but not both
+RelativeDateFormat_lastWeekFormat=Last {0,time,EEEE}, {0,time,short}
+# format for dates in the same month (should be similar to sameYearFormat, but also include the time of day)
+RelativeDateFormat_sameMonthFormat={0,date,MMM d}, {0,time,short}
+
+# format for dates in the same year (should be similar to oldFormat, but not include the year)
+RelativeDateFormat_sameYearFormat={0,date,MMM d}
+# format for old dates (should be similar to the result of DateFormat.getDateInstance(MEDIUM) and not include the time of day)
+RelativeDateFormat_oldFormat={0,date,medium}
Index: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.java
===================================================================
RCS file: src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.java
diff -N src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/team/internal/ccvs/ui/RelativeDateFormatMessages.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui;
+
+import org.eclipse.osgi.util.NLS;
+
+class RelativeDateFormatMessages extends NLS {
+ private static final String BUNDLE_NAME= "org.eclipse.team.internal.ccvs.ui.RelativeDateFormatMessages"; //$NON-NLS-1$
+
+ private RelativeDateFormatMessages() {
+ }
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, RelativeDateFormatMessages.class);
+ }
+ public static String RelativeDateFormat_lastWeekFormat;
+ public static String RelativeDateFormat_oldFormat;
+ public static String RelativeDateFormat_recentMinutesFormat;
+ public static String RelativeDateFormat_sameDayFormat;
+ public static String RelativeDateFormat_sameMinuteFormat;
+ public static String RelativeDateFormat_sameMonthFormat;
+ public static String RelativeDateFormat_sameWeekFormat;
+ public static String RelativeDateFormat_sameYearFormat;
+ public static String RelativeDateFormat_yesterdayFormat;
+}