[544905] Update to use relative time
Change-Id: I39adfd2451e85583a91b65c245d01c7aa03b7db2
Signed-off-by: Stephanie-Cao <stephanie.cao@ibm.com>
diff --git a/features/org.eclipse.wst.server_ui.feature/feature.xml b/features/org.eclipse.wst.server_ui.feature/feature.xml
index ad381b3..32d67ec 100644
--- a/features/org.eclipse.wst.server_ui.feature/feature.xml
+++ b/features/org.eclipse.wst.server_ui.feature/feature.xml
@@ -15,7 +15,7 @@
<feature
id="org.eclipse.wst.server_ui.feature"
label="%featureName"
- version="3.3.700.qualifier"
+ version="3.3.800.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="1.0.1.qualifier">
diff --git a/features/org.eclipse.wst.server_ui.feature/pom.xml b/features/org.eclipse.wst.server_ui.feature/pom.xml
index 199ed3b..7a8c832 100644
--- a/features/org.eclipse.wst.server_ui.feature/pom.xml
+++ b/features/org.eclipse.wst.server_ui.feature/pom.xml
@@ -22,7 +22,7 @@
<groupId>org.eclipse.webtools.servertools</groupId>
<artifactId>org.eclipse.wst.server_ui.feature</artifactId>
- <version>3.3.700-SNAPSHOT</version>
+ <version>3.3.800-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<build>
diff --git a/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
index 044d417..f0c91a2 100644
--- a/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.server.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.server.ui; singleton:=true
-Bundle-Version: 1.5.401.qualifier
+Bundle-Version: 1.5.500.qualifier
Bundle-Activator: org.eclipse.wst.server.ui.internal.ServerUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.wst.server.ui/pom.xml b/plugins/org.eclipse.wst.server.ui/pom.xml
index de1df2f..fbd88f5 100644
--- a/plugins/org.eclipse.wst.server.ui/pom.xml
+++ b/plugins/org.eclipse.wst.server.ui/pom.xml
@@ -22,6 +22,6 @@
<groupId>org.eclipse.webtools.servertools</groupId>
<artifactId>org.eclipse.wst.server.ui</artifactId>
- <version>1.5.401-SNAPSHOT</version>
+ <version>1.5.500-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
index 8a3e302..dcfc83c 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.java
@@ -390,6 +390,22 @@
public static String cacheUpdate_lastUpdatedOn;
public static String cacheUpdate_lastUpdatedFormat;
+ public static String secondsAgo;
+ public static String minutesAgo;
+ public static String hoursAgo;
+ public static String daysAgo;
+ public static String weeksAgo;
+ public static String monthsAgo;
+ public static String yearsAgo;
+ public static String secondAgo;
+ public static String minuteAgo;
+ public static String hourAgo;
+ public static String dayAgo;
+ public static String weekAgo;
+ public static String monthAgo;
+ public static String yearAgo;
+
+
static {
NLS.initializeMessages(ServerUIPlugin.PLUGIN_ID + ".internal.Messages", Messages.class);
}
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
index 2589ecf..125bc09 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/Messages.properties
@@ -531,11 +531,25 @@
cacheFrequency_daily=Daily
cacheUpdate_boxTitle=Downloadable server adapters cache update policy
cacheUpdate_refreshNow=&Refresh Now
-cacheUpdate_lastUpdatedOn=Last updated on:
+cacheUpdate_lastUpdatedOn=Last updated:
cacheUpdate_frequencyLabel=Update cache frequency:
cacheUpdate_refreshing=Refreshing ...
cacheUpdate_never=Never
# cacheUpdate_lastUpdatedFormat is the date format, which can be re-arranged to match the
# format of the locale. EEE = day of the week, MMM = month, yyyy = year, kk = hour, mm = minutes, ss = seconds
# zzz = time zone (e.g. EDT)
-cacheUpdate_lastUpdatedFormat=EEE MMM dd yyyy kk:mm:ss zzz
\ No newline at end of file
+cacheUpdate_lastUpdatedFormat=EEE MMM dd yyyy kk:mm:ss zzz
+secondsAgo={0} seconds ago
+minutesAgo={0} minutes ago
+hoursAgo={0} hours ago
+daysAgo={0} days ago
+weeksAgo={0} weeks ago
+monthsAgo={0} months ago
+yearsAgo={0} years ago
+secondAgo=a second ago
+minuteAgo=a minute ago
+hourAgo=an hour ago
+dayAgo=a day ago
+weekAgo=a week ago
+monthAgo=a month ago
+yearAgo=a year ago
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
index e346451..3712a0f 100644
--- a/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
+++ b/plugins/org.eclipse.wst.server.ui/serverui/org/eclipse/wst/server/ui/internal/ServerPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2017 IBM Corporation and others.
+ * Copyright (c) 2003, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -13,15 +13,14 @@
package org.eclipse.wst.server.ui.internal;
-import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
+import java.util.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -219,18 +218,76 @@
public String getLastUpdateDate() {
String lastUpdatedDate = Discovery.getLastUpdatedDate();
lastUpdatedDate = lastUpdatedDate.trim();
- // The cache's date is in English
- DateFormat dfCached = new SimpleDateFormat(CACHE_LAST_UPDATED_DATE_FORMAT, Locale.ENGLISH);
- // Need to covert the English date to the current locale's format
- DateFormat dfCurrLocale = new SimpleDateFormat(Messages.cacheUpdate_lastUpdatedFormat, Locale.getDefault());
-
- Date d;
+ SimpleDateFormat format = new SimpleDateFormat(CACHE_LAST_UPDATED_DATE_FORMAT, Locale.ENGLISH);
+ Date oldDate;
try {
- d = dfCached.parse(lastUpdatedDate);
- lastUpdatedDate = dfCurrLocale.format(d);
+ oldDate = format.parse(lastUpdatedDate);
+ Date now = new Date();
+ long diffInMillies = now.getTime() - oldDate.getTime();
+
+ long msPerMinute = 60 * 1000;
+ long msPerHour = msPerMinute * 60;
+ long msPerDay = msPerHour * 24;
+ long msPerWeek = msPerDay * 7;
+ long msPerMonth = msPerDay * 30;
+ long msPerYear = msPerDay * 365;
+ int value;
+ if (diffInMillies < msPerMinute) {
+ value = (int)diffInMillies/1000;
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.secondsAgo, value);
+ } else {
+ lastUpdatedDate = Messages.secondAgo;
+ }
+ }else if (diffInMillies < msPerHour) {
+ value =(int)(diffInMillies/msPerMinute);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.minutesAgo, value);
+ } else {
+ lastUpdatedDate = Messages.minuteAgo;
+ }
+ } else if (diffInMillies < msPerDay ) {
+ value = (int)(diffInMillies/msPerHour);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.hoursAgo, value);
+ } else {
+ lastUpdatedDate = Messages.hourAgo;
+ }
+ } else if (diffInMillies < msPerWeek) {
+ value = (int)(diffInMillies/msPerDay);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.daysAgo, value);
+ } else {
+ lastUpdatedDate = Messages.dayAgo;
+ }
+ } else if (diffInMillies < msPerMonth) {
+ value = (int)(diffInMillies/msPerWeek);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.weeksAgo, value);
+ } else {
+ lastUpdatedDate = Messages.weekAgo;
+ }
+ } else if (diffInMillies < msPerYear) {
+ value = (int)(diffInMillies/msPerMonth);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.monthsAgo, value);
+ } else {
+ lastUpdatedDate = Messages.monthAgo;
+ }
+ }else {
+ value = (int)(diffInMillies/msPerYear);
+ if (value > 1) {
+ lastUpdatedDate = NLS.bind(Messages.yearsAgo, value);
+ } else {
+ lastUpdatedDate =Messages.yearAgo;
+ }
+
+ }
+
} catch (ParseException e1) {
// In case of failure, display what was cached, so do nothing.
}
+
return lastUpdatedDate;
}
}
\ No newline at end of file