Make RelativeDateFormatter available to plugins
Change-Id: I9ab4a50c5eceec3a841c79f120ee67f428038cce Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
		@@ -63,3 +63,16 @@ java_library(
 | 
			
		||||
  name = 'diffy_image_files',
 | 
			
		||||
  resources = DIFFY,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
java_test(
 | 
			
		||||
  name = 'client_tests',
 | 
			
		||||
  srcs = glob(['src/test/java/**/*.java']),
 | 
			
		||||
  deps = [
 | 
			
		||||
    ':client',
 | 
			
		||||
    '//lib:junit',
 | 
			
		||||
    '//lib/jgit:jgit',
 | 
			
		||||
  ],
 | 
			
		||||
  source_under_test = [':client'],
 | 
			
		||||
  vm_args = ['-Xmx512m'],
 | 
			
		||||
  visibility = ['//tools/eclipse:classpath'],
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
// Copyright (C) 2015 The Android Open Source Project
 | 
			
		||||
//
 | 
			
		||||
// Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
// you may not use this file except in compliance with the License.
 | 
			
		||||
// You may obtain a copy of the License at
 | 
			
		||||
//
 | 
			
		||||
// http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
//
 | 
			
		||||
// Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
// See the License for the specific language governing permissions and
 | 
			
		||||
// limitations under the License.
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client;
 | 
			
		||||
 | 
			
		||||
import com.google.gwt.core.client.GWT;
 | 
			
		||||
import com.google.gwt.i18n.client.Constants;
 | 
			
		||||
 | 
			
		||||
public interface CommonConstants extends Constants {
 | 
			
		||||
  public static final CommonConstants C = GWT.create(CommonConstants.class);
 | 
			
		||||
 | 
			
		||||
  String inTheFuture();
 | 
			
		||||
  String month();
 | 
			
		||||
  String months();
 | 
			
		||||
  String year();
 | 
			
		||||
  String years();
 | 
			
		||||
 | 
			
		||||
  String oneSecondAgo();
 | 
			
		||||
  String oneMinuteAgo();
 | 
			
		||||
  String oneHourAgo();
 | 
			
		||||
  String oneDayAgo();
 | 
			
		||||
  String oneWeekAgo();
 | 
			
		||||
  String oneMonthAgo();
 | 
			
		||||
  String oneYearAgo();
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
inTheFuture = in the future
 | 
			
		||||
month = month
 | 
			
		||||
months = months
 | 
			
		||||
years = years
 | 
			
		||||
year = year
 | 
			
		||||
 | 
			
		||||
oneSecondAgo = 1 second ago
 | 
			
		||||
oneMinuteAgo = 1 minute ago
 | 
			
		||||
oneHourAgo = 1 hour ago
 | 
			
		||||
oneDayAgo = 1 day ago
 | 
			
		||||
oneWeekAgo = 1 week ago
 | 
			
		||||
oneMonthAgo = 1 month ago
 | 
			
		||||
oneYearAgo = 1 year ago
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
// Copyright (C) 2015 The Android Open Source Project
 | 
			
		||||
//
 | 
			
		||||
// Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
// you may not use this file except in compliance with the License.
 | 
			
		||||
// You may obtain a copy of the License at
 | 
			
		||||
//
 | 
			
		||||
// http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
//
 | 
			
		||||
// Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
// distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
// See the License for the specific language governing permissions and
 | 
			
		||||
// limitations under the License.
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client;
 | 
			
		||||
 | 
			
		||||
import com.google.gwt.core.client.GWT;
 | 
			
		||||
import com.google.gwt.i18n.client.Messages;
 | 
			
		||||
 | 
			
		||||
public interface CommonMessages extends Messages {
 | 
			
		||||
  public static final CommonMessages M = GWT.create(CommonMessages.class);
 | 
			
		||||
 | 
			
		||||
  String secondsAgo(long seconds);
 | 
			
		||||
  String minutesAgo(long minutes);
 | 
			
		||||
  String hoursAgo(long hours);
 | 
			
		||||
  String daysAgo(long days);
 | 
			
		||||
  String weeksAgo(long weeks);
 | 
			
		||||
  String monthsAgo(long months);
 | 
			
		||||
  String yearsAgo(long years);
 | 
			
		||||
  String years0MonthsAgo(long years, String yearLabel);
 | 
			
		||||
  String yearsMonthsAgo(long years, String yearLabel, long months,
 | 
			
		||||
      String monthLabel);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
secondsAgo = {0} seconds ago
 | 
			
		||||
minutesAgo = {0} minutes ago
 | 
			
		||||
hoursAgo = {0} hours ago
 | 
			
		||||
daysAgo = {0} days ago
 | 
			
		||||
weeksAgo = {0} weeks ago
 | 
			
		||||
monthsAgo = {0} months ago
 | 
			
		||||
years0MonthsAgo = {0} {1} ago
 | 
			
		||||
yearsMonthsAgo = {0} {1}, {2} {3} ago
 | 
			
		||||
yearsAgo = {0} years ago
 | 
			
		||||
@@ -14,7 +14,8 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.client;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.changes.Util;
 | 
			
		||||
import static com.google.gerrit.client.CommonConstants.C;
 | 
			
		||||
import static com.google.gerrit.client.CommonMessages.M;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
@@ -24,17 +25,11 @@ import java.util.Date;
 | 
			
		||||
 */
 | 
			
		||||
public class RelativeDateFormatter {
 | 
			
		||||
  static final long SECOND_IN_MILLIS = 1000;
 | 
			
		||||
 | 
			
		||||
  static final long MINUTE_IN_MILLIS = 60 * SECOND_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  static final long DAY_IN_MILLIS = 24 * HOUR_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  static final long WEEK_IN_MILLIS = 7 * DAY_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  static final long MONTH_IN_MILLIS = 30 * DAY_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  static final long YEAR_IN_MILLIS = 365 * DAY_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
@@ -48,16 +43,16 @@ public class RelativeDateFormatter {
 | 
			
		||||
 | 
			
		||||
    // shouldn't happen in a perfect world
 | 
			
		||||
    if (ageMillis < 0) {
 | 
			
		||||
      return Util.C.inTheFuture();
 | 
			
		||||
      return C.inTheFuture();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // seconds
 | 
			
		||||
    if (ageMillis < upperLimit(MINUTE_IN_MILLIS)) {
 | 
			
		||||
      long seconds = round(ageMillis, SECOND_IN_MILLIS);
 | 
			
		||||
      if (seconds == 1) {
 | 
			
		||||
        return Util.C.oneSecondAgo();
 | 
			
		||||
        return C.oneSecondAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.secondsAgo(seconds);
 | 
			
		||||
        return M.secondsAgo(seconds);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -65,9 +60,9 @@ public class RelativeDateFormatter {
 | 
			
		||||
    if (ageMillis < upperLimit(HOUR_IN_MILLIS)) {
 | 
			
		||||
      long minutes = round(ageMillis, MINUTE_IN_MILLIS);
 | 
			
		||||
      if (minutes == 1) {
 | 
			
		||||
        return Util.C.oneMinuteAgo();
 | 
			
		||||
        return C.oneMinuteAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.minutesAgo(minutes);
 | 
			
		||||
        return M.minutesAgo(minutes);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -75,9 +70,9 @@ public class RelativeDateFormatter {
 | 
			
		||||
    if (ageMillis < upperLimit(DAY_IN_MILLIS)) {
 | 
			
		||||
      long hours = round(ageMillis, HOUR_IN_MILLIS);
 | 
			
		||||
      if (hours == 1) {
 | 
			
		||||
        return Util.C.oneHourAgo();
 | 
			
		||||
        return C.oneHourAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.hoursAgo(hours);
 | 
			
		||||
        return M.hoursAgo(hours);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -85,9 +80,9 @@ public class RelativeDateFormatter {
 | 
			
		||||
    if (ageMillis < 14 * DAY_IN_MILLIS) {
 | 
			
		||||
      long days = round(ageMillis, DAY_IN_MILLIS);
 | 
			
		||||
      if (days == 1) {
 | 
			
		||||
        return Util.C.oneDayAgo();
 | 
			
		||||
        return C.oneDayAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.daysAgo(days);
 | 
			
		||||
        return M.daysAgo(days);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -95,9 +90,9 @@ public class RelativeDateFormatter {
 | 
			
		||||
    if (ageMillis < 10 * WEEK_IN_MILLIS) {
 | 
			
		||||
      long weeks = round(ageMillis, WEEK_IN_MILLIS);
 | 
			
		||||
      if (weeks == 1) {
 | 
			
		||||
        return Util.C.oneWeekAgo();
 | 
			
		||||
        return C.oneWeekAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.weeksAgo(weeks);
 | 
			
		||||
        return M.weeksAgo(weeks);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -105,32 +100,31 @@ public class RelativeDateFormatter {
 | 
			
		||||
    if (ageMillis < YEAR_IN_MILLIS) {
 | 
			
		||||
      long months = round(ageMillis, MONTH_IN_MILLIS);
 | 
			
		||||
      if (months == 1) {
 | 
			
		||||
        return Util.C.oneMonthAgo();
 | 
			
		||||
        return C.oneMonthAgo();
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.monthsAgo(months);
 | 
			
		||||
        return M.monthsAgo(months);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // up to 5 years use "year, months" rounded to months
 | 
			
		||||
    if (ageMillis < 5 * YEAR_IN_MILLIS) {
 | 
			
		||||
      long years = ageMillis / YEAR_IN_MILLIS;
 | 
			
		||||
      String yearLabel = (years > 1) ? Util.C.years() : Util.C.year();
 | 
			
		||||
      String yearLabel = (years > 1) ? C.years() : C.year();
 | 
			
		||||
      long months = round(ageMillis % YEAR_IN_MILLIS, MONTH_IN_MILLIS);
 | 
			
		||||
      String monthLabel =
 | 
			
		||||
          (months > 1) ? Util.C.months() : (months == 1 ? Util.C.month() : "");
 | 
			
		||||
      String monthLabel = (months > 1) ? C.months() : (months == 1 ? C.month() : "");
 | 
			
		||||
      if (months == 0) {
 | 
			
		||||
        return Util.M.years0MonthsAgo(years, yearLabel);
 | 
			
		||||
        return M.years0MonthsAgo(years, yearLabel);
 | 
			
		||||
      } else {
 | 
			
		||||
        return Util.M.yearsMonthsAgo(years, yearLabel, months, monthLabel);
 | 
			
		||||
        return M.yearsMonthsAgo(years, yearLabel, months, monthLabel);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // years
 | 
			
		||||
    long years = round(ageMillis, YEAR_IN_MILLIS);
 | 
			
		||||
    if (years == 1) {
 | 
			
		||||
      return Util.C.oneYearAgo();
 | 
			
		||||
      return C.oneYearAgo();
 | 
			
		||||
    } else {
 | 
			
		||||
      return Util.M.yearsAgo(years);
 | 
			
		||||
      return M.yearsAgo(years);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -19,6 +19,7 @@ import static com.google.gerrit.client.RelativeDateFormatter.HOUR_IN_MILLIS;
 | 
			
		||||
import static com.google.gerrit.client.RelativeDateFormatter.MINUTE_IN_MILLIS;
 | 
			
		||||
import static com.google.gerrit.client.RelativeDateFormatter.SECOND_IN_MILLIS;
 | 
			
		||||
import static com.google.gerrit.client.RelativeDateFormatter.YEAR_IN_MILLIS;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
import org.eclipse.jgit.util.RelativeDateFormatter;
 | 
			
		||||
@@ -61,7 +61,6 @@ java_test(
 | 
			
		||||
    '//lib/gwt:dev',
 | 
			
		||||
    '//lib/gwt:user',
 | 
			
		||||
    '//lib/gwt:gwt-test-utils',
 | 
			
		||||
    '//lib/jgit:jgit',
 | 
			
		||||
  ],
 | 
			
		||||
  source_under_test = [':ui_module'],
 | 
			
		||||
  vm_args = ['-Xmx512m'],
 | 
			
		||||
 
 | 
			
		||||
@@ -201,19 +201,5 @@ public interface ChangeConstants extends Constants {
 | 
			
		||||
  String diffAllSideBySide();
 | 
			
		||||
  String diffAllUnified();
 | 
			
		||||
 | 
			
		||||
  String inTheFuture();
 | 
			
		||||
  String month();
 | 
			
		||||
  String months();
 | 
			
		||||
  String year();
 | 
			
		||||
  String years();
 | 
			
		||||
 | 
			
		||||
  String oneSecondAgo();
 | 
			
		||||
  String oneMinuteAgo();
 | 
			
		||||
  String oneHourAgo();
 | 
			
		||||
  String oneDayAgo();
 | 
			
		||||
  String oneWeekAgo();
 | 
			
		||||
  String oneMonthAgo();
 | 
			
		||||
  String oneYearAgo();
 | 
			
		||||
 | 
			
		||||
  String votable();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -183,18 +183,4 @@ buttonClose = Close
 | 
			
		||||
diffAllSideBySide = All Side-by-Side
 | 
			
		||||
diffAllUnified = All Unified
 | 
			
		||||
 | 
			
		||||
inTheFuture = in the future
 | 
			
		||||
month = month
 | 
			
		||||
months = months
 | 
			
		||||
years = years
 | 
			
		||||
year = year
 | 
			
		||||
 | 
			
		||||
oneSecondAgo = 1 second ago
 | 
			
		||||
oneMinuteAgo = 1 minute ago
 | 
			
		||||
oneHourAgo = 1 hour ago
 | 
			
		||||
oneDayAgo = 1 day ago
 | 
			
		||||
oneWeekAgo = 1 week ago
 | 
			
		||||
oneMonthAgo = 1 month ago
 | 
			
		||||
oneYearAgo = 1 year ago
 | 
			
		||||
 | 
			
		||||
votable = Votable:
 | 
			
		||||
 
 | 
			
		||||
@@ -60,16 +60,5 @@ public interface ChangeMessages extends Messages {
 | 
			
		||||
  String groupHasTooManyMembers(String group);
 | 
			
		||||
  String groupManyMembersConfirmation(String group, int memberCount);
 | 
			
		||||
 | 
			
		||||
  String secondsAgo(long seconds);
 | 
			
		||||
  String minutesAgo(long minutes);
 | 
			
		||||
  String hoursAgo(long hours);
 | 
			
		||||
  String daysAgo(long days);
 | 
			
		||||
  String weeksAgo(long weeks);
 | 
			
		||||
  String monthsAgo(long months);
 | 
			
		||||
  String yearsAgo(long years);
 | 
			
		||||
  String years0MonthsAgo(long years, String yearLabel);
 | 
			
		||||
  String yearsMonthsAgo(long years, String yearLabel, long months,
 | 
			
		||||
      String monthLabel);
 | 
			
		||||
 | 
			
		||||
  String insertionsAndDeletions(int insertions, int deletions);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -43,14 +43,4 @@ groupIsNotAllowed =  The group {0} cannot be added as reviewer.
 | 
			
		||||
groupHasTooManyMembers = The group {0} has too many members to add them all as reviewers.
 | 
			
		||||
groupManyMembersConfirmation = The group {0} has {1} members. Do you want to add them all as reviewers?
 | 
			
		||||
 | 
			
		||||
secondsAgo = {0} seconds ago
 | 
			
		||||
minutesAgo = {0} minutes ago
 | 
			
		||||
hoursAgo = {0} hours ago
 | 
			
		||||
daysAgo = {0} days ago
 | 
			
		||||
weeksAgo = {0} weeks ago
 | 
			
		||||
monthsAgo = {0} months ago
 | 
			
		||||
years0MonthsAgo = {0} {1} ago
 | 
			
		||||
yearsMonthsAgo = {0} {1}, {2} {3} ago
 | 
			
		||||
yearsAgo = {0} years ago
 | 
			
		||||
 | 
			
		||||
insertionsAndDeletions = +{0}, -{1}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ package com.google.gerrit.plugin.client;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.client.AccountFormatter;
 | 
			
		||||
import com.google.gerrit.client.DateFormatter;
 | 
			
		||||
import com.google.gerrit.client.RelativeDateFormatter;
 | 
			
		||||
import com.google.gerrit.client.info.AccountInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
@@ -44,6 +45,11 @@ public class FormatUtil {
 | 
			
		||||
    return new DateFormatter(Plugin.get().getUserPreferences());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Format a date using git log's relative date format. */
 | 
			
		||||
  public static String relativeFormat(Date dt) {
 | 
			
		||||
    return RelativeDateFormatter.format(dt);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Formats an account as a name and an email address.
 | 
			
		||||
   * <p>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user