Bug 544904: Japanese Calendar - Wrong Japanese era of Data tag in CVS
repos view

This fix modifies the display string for Date if the year is not just a
number. This handles the case for Japanese Calendar

Change-Id: If85725e0da3a1d3de6c06135937d74e8f8f9b6c0
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSTagElement.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSTagElement.java
index 5ff8cbf..d678a5f 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSTagElement.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/CVSTagElement.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@
 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
 import org.eclipse.ui.progress.IElementCollector;
 
+import com.ibm.icu.text.DateFormat;
 import com.ibm.icu.text.SimpleDateFormat;
 import com.ibm.icu.util.TimeZone;
 
@@ -43,15 +44,34 @@
 	private static final String TIME_ONLY_COLUMN_FORMAT = "HH:mm:ss"; //$NON-NLS-1$
 	private static SimpleDateFormat localLongFormat = new SimpleDateFormat(REPO_VIEW_LONG_FORAMT,Locale.getDefault());
 	private static SimpleDateFormat localShortFormat = new SimpleDateFormat(REPO_VIEW_SHORT_FORMAT,Locale.getDefault());
+	private static DateFormat localLongDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);
+	private static DateFormat localShortDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
+	private static DateFormat localYearDateFormat = DateFormat.getInstanceForSkeleton(DateFormat.YEAR);
 	private static SimpleDateFormat timeColumnFormat = new SimpleDateFormat(TIME_ONLY_COLUMN_FORMAT, Locale.getDefault());
 
 	static synchronized public String toDisplayString(Date date){
+		String year = localYearDateFormat.format(date);
+		boolean permitSimpleDateFormat = true;
+		try {
+			Integer.parseInt(year);			
+		} catch (NumberFormatException e) {
+			// This can happen if the Year is not a number but also includes an Era eg: JapaneseCalendar
+			permitSimpleDateFormat = false;
+		}
+		DateFormat selectedFormat = localLongFormat;
+		if (!permitSimpleDateFormat) {
+			selectedFormat = localLongDateFormat;
+		}
 		String localTime = timeColumnFormat.format(date);
 		timeColumnFormat.setTimeZone(TimeZone.getDefault());
 		if(localTime.equals("00:00:00")){ //$NON-NLS-1$
-			return localShortFormat.format(date);
+			if (permitSimpleDateFormat) {
+				selectedFormat = localShortFormat;
+			} else {
+				selectedFormat = localShortDateFormat;
+			}
 		}
-		return localLongFormat.format(date);
+		return selectedFormat.format(date);
 	}
 	
 	public CVSTagElement(CVSTag tag, ICVSRepositoryLocation root) {