TimeUtils needs to output localized strings like "5 days ago" and "6 months". In order to do this it needs a translation resource. Additionally, that resource can not be static because the single Gitblit server can handle multiple connections in different locales/languages.
TimeUtils has changed from a collection of static methods to some static methods and some instance methods. A TimeUtils is instantiated with an optional resource bundle which contains the preferred translation. If the resourec bundle is null or the requested translation key does not exist, an English default will be used.
This change required adjusting the signatures of several key methods and that cascaded out to adjusting those methods calls in many, many classes.
private static final long serialVersionUID = 1L;\r
\r
private final String pattern;\r
-\r
+ \r
public DateCellRenderer(String pattern, Color foreground) {\r
this.pattern = (pattern == null ? "yyyy-MM-dd HH:mm" : pattern);\r
setForeground(foreground);\r
title = "--";\r
dateString = "never";\r
} else {\r
- title = TimeUtils.timeAgo(date);\r
+ title = Translation.getTimeUtils().timeAgo(date);\r
dateString = new SimpleDateFormat(pattern).format((Date) value);\r
}\r
\r
import com.gitblit.Constants.RpcRequest;\r
import com.gitblit.models.ServerStatus;\r
import com.gitblit.utils.ByteFormat;\r
-import com.gitblit.utils.TimeUtils;\r
\r
/**\r
* This panel displays the server status.\r
ServerStatus status = gitblit.getStatus();\r
header.setText(Translation.get("gb.status"));\r
version.setText(Constants.NAME + (status.isGO ? " GO v" : " WAR v") + status.version);\r
- releaseDate.setText(status.releaseDate);\r
- bootDate.setText(status.bootDate.toString() + " (" + TimeUtils.timeAgo(status.bootDate)\r
+ releaseDate.setText(status.releaseDate); \r
+ bootDate.setText(status.bootDate.toString() + " (" + Translation.getTimeUtils().timeAgo(status.bootDate)\r
+ ")");\r
url.setText(gitblit.url);\r
servletContainer.setText(status.servletContainer);\r
import java.util.MissingResourceException;\r
import java.util.ResourceBundle;\r
\r
+import com.gitblit.utils.TimeUtils;\r
+\r
/**\r
* Loads the Gitblit language resource file.\r
* \r
public class Translation {\r
\r
private final static ResourceBundle translation;\r
+ \r
+ private final static TimeUtils timeUtils;\r
\r
static {\r
ResourceBundle bundle;\r
bundle = ResourceBundle.getBundle("GitBlitWebApp");\r
}\r
translation = bundle;\r
+ \r
+ timeUtils = new TimeUtils(translation);\r
}\r
\r
public static String get(String key) {\r
}\r
return key;\r
}\r
+ \r
+ public static TimeUtils getTimeUtils() {\r
+ return timeUtils;\r
+ }\r
}\r
\r
@Override\r
public String toString() {\r
- StringBuilder sb = new StringBuilder();\r
- sb.append(TimeUtils.timeAgo(created));\r
+ StringBuilder sb = new StringBuilder(); \r
+ sb.append(new TimeUtils().timeAgo(created));\r
switch (code) {\r
case '+':\r
sb.append(" created by ");\r
*/\r
package com.gitblit.utils;\r
\r
+import java.text.MessageFormat;\r
import java.text.SimpleDateFormat;\r
import java.util.Calendar;\r
import java.util.Date;\r
+import java.util.ResourceBundle;\r
\r
/**\r
* Utility class of time functions.\r
public static final long ONEDAY = ONEHOUR * 24L;\r
\r
public static final long ONEYEAR = ONEDAY * 365L;\r
+ \r
+ private final ResourceBundle translation;\r
+ \r
+ public TimeUtils() {\r
+ this(null);\r
+ }\r
+ \r
+ public TimeUtils(ResourceBundle translation) {\r
+ this.translation = translation;\r
+ }\r
\r
/**\r
* Returns true if date is today.\r
* @param days\r
* @return duration as string in days, months, and/or years\r
*/\r
- public static String duration(int days) {\r
+ public String duration(int days) {\r
if (days <= 60) {\r
- return days + (days > 1 ? " days" : " day");\r
+ return (days > 1 ? translate(days, "gb.duration.days", "{0} days") : translate("gb.duration.oneDay", "1 day"));\r
} else if (days < 365) {\r
int rem = days % 30;\r
- return ((days / 30) + (rem >= 15 ? 1 : 0)) + " months";\r
+ return translate(((days / 30) + (rem >= 15 ? 1 : 0)), "gb.duration.months", "{0} months");\r
} else {\r
int years = days / 365;\r
int rem = days % 365;\r
- String yearsString = years + (years > 1 ? " years" : " year");\r
+ String yearsString = (years > 1 ? translate(years, "gb.duration.years", "{0} years") : translate("gb.duration.oneYear", "1 year"));\r
if (rem < 30) {\r
if (rem == 0) {\r
return yearsString;\r
} else {\r
- return yearsString + (rem >= 15 ? ", 1 month" : "");\r
+ return yearsString + (rem >= 15 ? (", " + translate("gb.duration.oneMonth", "1 month")): "");\r
}\r
} else {\r
int months = rem / 30;\r
if (remDays >= 15) {\r
months++;\r
}\r
- String monthsString = yearsString + ", " + months\r
- + (months > 1 ? " months" : " month");\r
+ String monthsString = yearsString + ", "\r
+ + (months > 1 ? translate(months, "gb.duration.months", "{0} months") : translate("gb.duration.oneMonth", "1 month"));\r
return monthsString;\r
}\r
}\r
return days;\r
}\r
\r
+ public String today() {\r
+ return translate("gb.time.today", "today");\r
+ }\r
+\r
+ public String yesterday() {\r
+ return translate("gb.time.yesterday", "yesterday");\r
+ }\r
+\r
/**\r
* Returns the string representation of the duration between now and the\r
* date.\r
* @param date\r
* @return duration as a string\r
*/\r
- public static String timeAgo(Date date) {\r
+ public String timeAgo(Date date) {\r
return timeAgo(date, false);\r
}\r
\r
* @param date\r
* @return the css class\r
*/\r
- public static String timeAgoCss(Date date) {\r
+ public String timeAgoCss(Date date) {\r
return timeAgo(date, true);\r
}\r
\r
* @param css\r
* @return the string representation of the duration OR the css class\r
*/\r
- private static String timeAgo(Date date, boolean css) {\r
+ private String timeAgo(Date date, boolean css) {\r
if (isToday(date) || isYesterday(date)) {\r
int mins = minutesAgo(date, true);\r
if (mins >= 120) {\r
}\r
int hours = hoursAgo(date, true);\r
if (hours > 23) {\r
- return "yesterday";\r
+ return yesterday();\r
} else {\r
- return hours + " hours ago";\r
+ return translate(hours, "gb.time.hoursAgo", "{0} hours ago");\r
}\r
}\r
if (css) {\r
return "age0";\r
}\r
- return mins + " min" + (mins > 1 ? "s" : "") + " ago";\r
+ if (mins > 2) {\r
+ return translate(mins, "gb.time.minsAgo", "{0} mins ago");\r
+ }\r
+ return translate("gb.time.justNow", "just now");\r
} else {\r
int days = daysAgo(date);\r
if (css) {\r
}\r
if (days < 365) {\r
if (days <= 30) {\r
- return days + " days ago";\r
+ return translate(days, "gb.time.daysAgo", "{0} days ago");\r
} else if (days <= 90) {\r
int weeks = days / 7;\r
if (weeks == 12) {\r
- return "3 months ago";\r
+ return translate(3, "gb.time.monthsAgo", "{0} months ago");\r
} else {\r
- return weeks + " weeks ago";\r
+ return translate(weeks, "gb.time.weeksAgo", "{0} weeks ago");\r
}\r
}\r
int months = days / 30;\r
if (weeks >= 2) {\r
months++;\r
}\r
- return months + " months ago";\r
+ return translate(months, "gb.time.monthsAgo", "{0} months ago");\r
} else if (days == 365) {\r
- return "1 year ago";\r
+ return translate("gb.time.oneYearAgo", "1 year ago");\r
} else {\r
int yr = days / 365;\r
days = days % 365;\r
int months = (yr * 12) + (days / 30);\r
if (months > 23) {\r
- return yr + " years ago";\r
+ return translate(yr, "gb.time.yearsAgo", "{0} years ago");\r
} else {\r
- return months + " months ago";\r
+ return translate(months, "gb.time.monthsAgo", "{0} months ago");\r
}\r
}\r
}\r
}\r
+ \r
+ private String translate(String key, String defaultValue) {\r
+ String value = defaultValue;\r
+ if (translation != null && translation.containsKey(key)) {\r
+ String aValue = translation.getString(key);\r
+ if (!StringUtils.isEmpty(aValue)) {\r
+ value = aValue;\r
+ }\r
+ }\r
+ return value;\r
+ }\r
+ \r
+ private String translate(int val, String key, String defaultPattern) {\r
+ String pattern = defaultPattern;\r
+ if (translation != null && translation.containsKey(key)) {\r
+ String aValue = translation.getString(key);\r
+ if (!StringUtils.isEmpty(aValue)) {\r
+ pattern = aValue;\r
+ }\r
+ }\r
+ return MessageFormat.format(pattern, val);\r
+ }\r
\r
/**\r
* Convert a frequency string into minutes.\r
return params.getString("n", "");\r
}\r
\r
- public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone) {\r
+ public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {\r
String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy");\r
DateFormat df = new SimpleDateFormat(format);\r
if (timeZone == null) {\r
String title = null;\r
if (date.getTime() <= System.currentTimeMillis()) {\r
// past\r
- title = TimeUtils.timeAgo(date);\r
+ title = timeUtils.timeAgo(date);\r
}\r
if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {\r
String tmp = dateString;\r
title = tmp;\r
}\r
Label label = new Label(wicketId, dateString);\r
- WicketUtils.setCssClass(label, TimeUtils.timeAgoCss(date));\r
+ WicketUtils.setCssClass(label, timeUtils.timeAgoCss(date));\r
if (!StringUtils.isEmpty(title)) {\r
WicketUtils.setHtmlTooltip(label, title);\r
}\r
return label;\r
}\r
\r
- public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone) {\r
+ public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {\r
String format = GitBlit.getString(Keys.web.timeFormat, "HH:mm");\r
DateFormat df = new SimpleDateFormat(format);\r
if (timeZone == null) {\r
} else {\r
timeString = df.format(date);\r
}\r
- String title = TimeUtils.timeAgo(date);\r
+ String title = timeUtils.timeAgo(date);\r
Label label = new Label(wicketId, timeString);\r
if (!StringUtils.isEmpty(title)) {\r
WicketUtils.setHtmlTooltip(label, title);\r
return label;\r
}\r
\r
- public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone) {\r
+ public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {\r
String format = GitBlit.getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");\r
DateFormat df = new SimpleDateFormat(format);\r
if (timeZone == null) {\r
}\r
String title = null;\r
if (TimeUtils.isToday(date)) {\r
- title = "today";\r
+ title = timeUtils.today();\r
} else if (TimeUtils.isYesterday(date)) {\r
- title = "yesterday";\r
+ title = timeUtils.yesterday();\r
} else if (date.getTime() <= System.currentTimeMillis()) {\r
// past\r
- title = TimeUtils.timeAgo(date);\r
+ title = timeUtils.timeAgo(date);\r
}\r
if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {\r
String tmp = dateString;\r
return label;\r
}\r
\r
- public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone) {\r
+ public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {\r
String format = GitBlit.getString(Keys.web.datetimestampLongFormat,\r
"EEEE, MMMM d, yyyy HH:mm Z");\r
DateFormat df = new SimpleDateFormat(format);\r
String title = null;\r
if (date.getTime() <= System.currentTimeMillis()) {\r
// past\r
- title = TimeUtils.timeAgo(date);\r
+ title = timeUtils.timeAgo(date);\r
}\r
Label label = new Label(wicketId, dateString);\r
if (!StringUtils.isEmpty(title)) {\r
\r
import java.util.LinkedHashMap;\r
import java.util.Map;\r
+import java.util.ResourceBundle;\r
import java.util.TimeZone;\r
\r
import javax.servlet.http.Cookie;\r
import com.gitblit.Keys;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.TimeUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.LinkPanel;\r
public abstract class BasePage extends WebPage {\r
\r
private final Logger logger;\r
+ \r
+ private transient TimeUtils timeUtils;\r
\r
public BasePage() {\r
super();\r
}\r
}\r
\r
+ protected String getLanguageCode() {\r
+ return GitBlitWebSession.get().getLocale().getLanguage();\r
+ }\r
+ \r
+ protected TimeUtils getTimeUtils() {\r
+ if (timeUtils == null) {\r
+ ResourceBundle bundle; \r
+ try {\r
+ bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", GitBlitWebSession.get().getLocale());\r
+ } catch (Throwable t) {\r
+ bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp");\r
+ }\r
+ timeUtils = new TimeUtils(bundle);\r
+ }\r
+ return timeUtils;\r
+ }\r
+ \r
@Override\r
protected void onBeforeRender() {\r
if (GitBlit.isDebugMode()) {\r
// author\r
add(createPersonPanel("commitAuthor", c.getAuthorIdent(), Constants.SearchType.AUTHOR));\r
add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(),\r
- getTimeZone()));\r
+ getTimeZone(), getTimeUtils()));\r
\r
// committer\r
add(createPersonPanel("commitCommitter", c.getCommitterIdent(), Constants.SearchType.COMMITTER));\r
add(WicketUtils.createTimestampLabel("commitCommitterDate",\r
- c.getCommitterIdent().getWhen(), getTimeZone()));\r
+ c.getCommitterIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
\r
add(new Label("commitId", c.getName()));\r
\r
Constants.SearchType.AUTHOR));\r
item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));\r
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef\r
- .getAuthorIdent().getWhen(), getTimeZone()));\r
+ .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
item.add(new Label("noteContent", GitBlit.self().processCommitMessage(\r
repositoryName, entry.content)).setEscapeModelStrings(false));\r
}\r
add(new Label("frequency", registration.frequency));\r
add(new Label("folder", registration.folder));\r
add(new Label("token", showAdmin ? registration.token : "--"));\r
- add(WicketUtils.createTimestampLabel("lastPull", registration.lastPull, getTimeZone()));\r
- add(WicketUtils.createTimestampLabel("nextPull", registration.nextPull, getTimeZone()));\r
+ add(WicketUtils.createTimestampLabel("lastPull", registration.lastPull, getTimeZone(), getTimeUtils()));\r
+ add(WicketUtils.createTimestampLabel("nextPull", registration.nextPull, getTimeZone(), getTimeUtils()));\r
\r
StringBuilder inclusions = new StringBuilder();\r
for (String inc : registration.inclusions) {\r
item.add(new LinkPanel("branch", "branch", StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class, WicketUtils.newObjectParameter(sr.repository, sr.branch)));\r
}\r
item.add(new Label("author", sr.author));\r
- item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone()));\r
+ item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));\r
}\r
};\r
add(resultsView.setVisible(results.size() > 0));\r
import com.gitblit.models.Metric;\r
import com.gitblit.utils.MetricUtils;\r
import com.gitblit.utils.StringUtils;\r
-import com.gitblit.utils.TimeUtils;\r
import com.gitblit.wicket.WicketUtils;\r
\r
public class MetricsPage extends RepositoryPage {\r
} else {\r
add(new Label("branchStats",\r
MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,\r
- metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));\r
+ metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));\r
}\r
insertLinePlot("commitsChart", metrics);\r
insertBarPlot("dayOfWeekChart", getDayOfWeekMetrics(r, objectId));\r
\r
add(new Label("url", proposal.url));\r
add(new Label("message", proposal.message));\r
- add(WicketUtils.createTimestampLabel("received", proposal.received, getTimeZone()));\r
+ add(WicketUtils.createTimestampLabel("received", proposal.received, getTimeZone(), getTimeUtils()));\r
add(new Label("token", proposal.token));\r
add(new Label("tokenType", proposal.tokenType.name()));\r
\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.MarkdownUtils;\r
import com.gitblit.utils.StringUtils;\r
-import com.gitblit.utils.TimeUtils;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.BranchesPanel;\r
import com.gitblit.wicket.panels.LogPanel;\r
add(new Label("repositoryOwner", getRepositoryModel().owner));\r
\r
add(WicketUtils.createTimestampLabel("repositoryLastChange",\r
- JGitUtils.getLastChange(r), getTimeZone()));\r
+ JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));\r
if (metricsTotal == null) {\r
add(new Label("branchStats", ""));\r
} else {\r
add(new Label("branchStats",\r
MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,\r
- metricsTotal.tag, TimeUtils.duration(metricsTotal.duration))));\r
+ metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));\r
}\r
add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,\r
WicketUtils.newRepositoryParameter(repositoryName)));\r
if (tagRef.getAuthorIdent() != null) {\r
when = tagRef.getAuthorIdent().getWhen();\r
}\r
- add(WicketUtils.createTimestampLabel("tagDate", when, getTimeZone()));\r
+ add(WicketUtils.createTimestampLabel("tagDate", when, getTimeZone(), getTimeUtils()));\r
\r
addFullText("fullMessage", tagRef.getFullMessage(), true);\r
}\r
add(new Label("ticketTitle", t.title));\r
add(new Label("ticketId", t.id));\r
add(new Label("ticketHandler", t.handler.toLowerCase()));\r
- add(WicketUtils.createTimestampLabel("ticketOpenDate", t.date, getTimeZone()));\r
+ add(WicketUtils.createTimestampLabel("ticketOpenDate", t.date, getTimeZone(), getTimeUtils()));\r
Label stateLabel = new Label("ticketState", t.state);\r
WicketUtils.setTicketCssClass(stateLabel, t.state);\r
add(stateLabel);\r
public void populateItem(final Item<Comment> item) {\r
final Comment entry = item.getModelObject();\r
item.add(WicketUtils.createDateLabel("commentDate", entry.date, GitBlitWebSession\r
- .get().getTimezone()));\r
+ .get().getTimezone(), getTimeUtils()));\r
item.add(new Label("commentAuthor", entry.author.toLowerCase()));\r
item.add(new Label("commentText", prepareComment(entry.text))\r
.setEscapeModelStrings(false));\r
WicketUtils.setTicketCssClass(stateLabel, entry.state);\r
item.add(stateLabel);\r
item.add(WicketUtils.createDateLabel("ticketDate", entry.date, GitBlitWebSession\r
- .get().getTimezone()));\r
+ .get().getTimezone(), getTimeUtils()));\r
item.add(new Label("ticketHandler", StringUtils.trimString(\r
entry.handler.toLowerCase(), 30)));\r
item.add(new LinkPanel("ticketTitle", "list subject", StringUtils.trimString(\r
\r
public void populateItem(final Item<Activity> activityItem) {\r
final Activity entry = activityItem.getModelObject();\r
- activityItem.add(WicketUtils.createDatestampLabel("title", entry.startDate, getTimeZone()));\r
+ activityItem.add(WicketUtils.createDatestampLabel("title", entry.startDate, getTimeZone(), getTimeUtils()));\r
\r
// display the commits in chronological order\r
DataView<RepositoryCommit> commits = new DataView<RepositoryCommit>("commit",\r
\r
// commit time of day\r
commitItem.add(WicketUtils.createTimeLabel("time", commit.getCommitterIdent()\r
- .getWhen(), getTimeZone()));\r
+ .getWhen(), getTimeZone(), getTimeUtils()));\r
\r
// avatar\r
commitItem.add(new GravatarImage("avatar", commit.getAuthorIdent(), 36));\r
*/\r
package com.gitblit.wicket.panels;\r
\r
+import java.util.ResourceBundle;\r
import java.util.TimeZone;\r
\r
import org.apache.wicket.AttributeModifier;\r
import com.gitblit.Constants;\r
import com.gitblit.GitBlit;\r
import com.gitblit.Keys;\r
+import com.gitblit.utils.TimeUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
\r
public abstract class BasePanel extends Panel {\r
\r
private static final long serialVersionUID = 1L;\r
+ \r
+ private transient TimeUtils timeUtils;\r
\r
public BasePanel(String wicketId) {\r
super(wicketId);\r
return GitBlit.getBoolean(Keys.web.useClientTimezone, false) ? GitBlitWebSession.get()\r
.getTimezone() : GitBlit.getTimezone();\r
}\r
+ \r
+ protected TimeUtils getTimeUtils() {\r
+ if (timeUtils == null) {\r
+ ResourceBundle bundle; \r
+ try {\r
+ bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", GitBlitWebSession.get().getLocale());\r
+ } catch (Throwable t) {\r
+ bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp");\r
+ }\r
+ timeUtils = new TimeUtils(bundle);\r
+ }\r
+ return timeUtils;\r
+ }\r
\r
protected void setPersonSearchTooltip(Component component, String value, Constants.SearchType searchType) {\r
if (searchType.equals(Constants.SearchType.AUTHOR)) {\r
public void populateItem(final Item<RefModel> item) {\r
final RefModel entry = item.getModelObject();\r
\r
- item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone(), getTimeUtils()));\r
\r
item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(\r
entry.displayName, 28), LogPage.class, WicketUtils.newObjectParameter(\r
WicketUtils.newObjectParameter(repositoryName, c.getName())));\r
add(new Label("commitid", c.getName()));\r
add(new Label("author", c.getAuthorIdent().getName()));\r
- add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone()));\r
+ add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
add(new GravatarImage("authorAvatar", c.getAuthorIdent()));\r
}\r
}
\ No newline at end of file
final FederationProposal entry = item.getModelObject();\r
item.add(new LinkPanel("url", "list", entry.url, ReviewProposalPage.class,\r
WicketUtils.newTokenParameter(entry.token)));\r
- item.add(WicketUtils.createDateLabel("received", entry.received, getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("received", entry.received, getTimeZone(), getTimeUtils()));\r
item.add(new Label("tokenType", entry.tokenType.name()));\r
item.add(new LinkPanel("token", "list", entry.token, ReviewProposalPage.class,\r
WicketUtils.newTokenParameter(entry.token)));\r
\r
item.add(WicketUtils.getRegistrationImage("typeIcon", entry, this));\r
\r
- item.add(WicketUtils.createDateLabel("lastPull", entry.lastPull, getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("lastPull", entry.lastPull, getTimeZone(), getTimeUtils()));\r
item.add(WicketUtils\r
- .createTimestampLabel("nextPull", entry.nextPull, getTimeZone()));\r
+ .createTimestampLabel("nextPull", entry.nextPull, getTimeZone(), getTimeUtils()));\r
item.add(new Label("frequency", entry.frequency));\r
WicketUtils.setAlternatingBackground(item, counter);\r
counter++;\r
final RevCommit entry = item.getModelObject();\r
final Date date = JGitUtils.getCommitDate(entry);\r
\r
- item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));\r
\r
// author search link\r
String author = entry.getAuthorIdent().getName();\r
final RevCommit entry = item.getModelObject();\r
final Date date = JGitUtils.getCommitDate(entry);\r
\r
- item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));\r
\r
// author search link\r
String author = entry.getAuthorIdent().getName();\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
-import com.gitblit.utils.TimeUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.pages.BasePage;\r
if (entry.lastChange.getTime() == 0) {\r
lastChange = "--";\r
} else {\r
- lastChange = TimeUtils.timeAgo(entry.lastChange);\r
+ lastChange = getTimeUtils().timeAgo(entry.lastChange);\r
}\r
Label lastChangeLabel = new Label("repositoryLastChange", lastChange);\r
row.add(lastChangeLabel);\r
- WicketUtils.setCssClass(lastChangeLabel, TimeUtils.timeAgoCss(entry.lastChange));\r
+ WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));\r
\r
boolean showOwner = user != null && user.username.equalsIgnoreCase(entry.owner);\r
if (showAdmin) {\r
final RevCommit entry = item.getModelObject();\r
final Date date = JGitUtils.getCommitDate(entry);\r
\r
- item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));\r
\r
// author search link\r
String author = entry.getAuthorIdent().getName();\r
public void populateItem(final Item<RefModel> item) {\r
RefModel entry = item.getModelObject();\r
\r
- item.add(WicketUtils.createDateLabel("tagDate", entry.getDate(), getTimeZone()));\r
+ item.add(WicketUtils.createDateLabel("tagDate", entry.getDate(), getTimeZone(), getTimeUtils()));\r
\r
Class<? extends RepositoryPage> linkClass;\r
switch (entry.getReferencedObjectType()) {\r
\r
@Test\r
public void testDurations() throws Exception {\r
- assertEquals("1 day", TimeUtils.duration(1));\r
- assertEquals("5 days", TimeUtils.duration(5));\r
- assertEquals("3 months", TimeUtils.duration(75));\r
- assertEquals("12 months", TimeUtils.duration(364));\r
- assertEquals("1 year", TimeUtils.duration(365 + 0));\r
- assertEquals("1 year", TimeUtils.duration(365 + 10));\r
- assertEquals("1 year, 1 month", TimeUtils.duration(365 + 15));\r
- assertEquals("1 year, 1 month", TimeUtils.duration(365 + 30));\r
- assertEquals("1 year, 1 month", TimeUtils.duration(365 + 44));\r
- assertEquals("1 year, 2 months", TimeUtils.duration(365 + 45));\r
- assertEquals("1 year, 2 months", TimeUtils.duration(365 + 60));\r
-\r
- assertEquals("2 years", TimeUtils.duration(2 * 365 + 0));\r
- assertEquals("2 years", TimeUtils.duration(2 * 365 + 10));\r
- assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 15));\r
- assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 30));\r
- assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 44));\r
- assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 45));\r
- assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 60));\r
+ TimeUtils timeUtils = new TimeUtils();\r
+ assertEquals("1 day", timeUtils.duration(1));\r
+ assertEquals("5 days", timeUtils.duration(5));\r
+ assertEquals("3 months", timeUtils.duration(75));\r
+ assertEquals("12 months", timeUtils.duration(364));\r
+ assertEquals("1 year", timeUtils.duration(365 + 0));\r
+ assertEquals("1 year", timeUtils.duration(365 + 10));\r
+ assertEquals("1 year, 1 month", timeUtils.duration(365 + 15));\r
+ assertEquals("1 year, 1 month", timeUtils.duration(365 + 30));\r
+ assertEquals("1 year, 1 month", timeUtils.duration(365 + 44));\r
+ assertEquals("1 year, 2 months", timeUtils.duration(365 + 45));\r
+ assertEquals("1 year, 2 months", timeUtils.duration(365 + 60));\r
+\r
+ assertEquals("2 years", timeUtils.duration(2 * 365 + 0));\r
+ assertEquals("2 years", timeUtils.duration(2 * 365 + 10));\r
+ assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 15));\r
+ assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 30));\r
+ assertEquals("2 years, 1 month", timeUtils.duration(2 * 365 + 44));\r
+ assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 45));\r
+ assertEquals("2 years, 2 months", timeUtils.duration(2 * 365 + 60));\r
}\r
\r
@Test\r
public void testTimeAgo() throws Exception {\r
// standard time ago tests\r
- assertEquals("1 min ago", TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)));\r
- assertEquals("60 mins ago", TimeUtils.timeAgo(offset(60 * TimeUtils.MIN)));\r
- assertEquals("2 hours ago", TimeUtils.timeAgo(offset(120 * TimeUtils.MIN)));\r
- assertEquals("15 hours ago", TimeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)));\r
- assertEquals("yesterday", TimeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)));\r
- assertEquals("2 days ago", TimeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)));\r
- assertEquals("5 weeks ago", TimeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)));\r
- assertEquals("3 months ago", TimeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)));\r
- assertEquals("3 months ago", TimeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)));\r
- assertEquals("4 months ago", TimeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)));\r
- assertEquals("1 year ago", TimeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)));\r
- assertEquals("13 months ago", TimeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)));\r
- assertEquals("2 years ago", TimeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)));\r
+ TimeUtils timeUtils = new TimeUtils();\r
+ assertEquals("just now", timeUtils.timeAgo(offset(1 * TimeUtils.MIN)));\r
+ assertEquals("60 mins ago", timeUtils.timeAgo(offset(60 * TimeUtils.MIN)));\r
+ assertEquals("2 hours ago", timeUtils.timeAgo(offset(120 * TimeUtils.MIN)));\r
+ assertEquals("15 hours ago", timeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)));\r
+ assertEquals("yesterday", timeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)));\r
+ assertEquals("2 days ago", timeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)));\r
+ assertEquals("5 weeks ago", timeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)));\r
+ assertEquals("3 months ago", timeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)));\r
+ assertEquals("3 months ago", timeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)));\r
+ assertEquals("4 months ago", timeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)));\r
+ assertEquals("1 year ago", timeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)));\r
+ assertEquals("13 months ago", timeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)));\r
+ assertEquals("2 years ago", timeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)));\r
\r
// css class tests\r
- assertEquals("age0", TimeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)));\r
- assertEquals("age0", TimeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)));\r
- assertEquals("age1", TimeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)));\r
- assertEquals("age1", TimeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)));\r
- assertEquals("age2", TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));\r
+ assertEquals("age0", timeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)));\r
+ assertEquals("age0", timeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)));\r
+ assertEquals("age1", timeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)));\r
+ assertEquals("age1", timeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)));\r
+ assertEquals("age2", timeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));\r
}\r
\r
@Test\r