Skip to content

Commit

Permalink
Localise relative times (final bit of localisation for issue #28 ?)
Browse files Browse the repository at this point in the history
I am now officially in love with this method for formatting relative times:

http://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeTimeSpanString(long)

- allows me to delete a big ugly method. Hurrah!
  • Loading branch information
rtyley committed Jul 29, 2011
1 parent 3aa5541 commit 4a41b1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RepositoryViewHolder(View v) {

public void updateViewFor(RepoSummary repoSummary) {
title.setText(niceNameFor(repoSummary.getRepo()));
String commitTimeText="...";
CharSequence commitTimeText="...";
RevCommit latestCommit = repoSummary.getLatestCommit();
if (latestCommit!=null) {
detail.setText(repoSummary.getLatestCommit().getShortMessage());
Expand Down
45 changes: 7 additions & 38 deletions agit/src/main/java/com/madgag/agit/util/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,16 @@
package com.madgag.agit.util;


import android.text.format.DateUtils;

import static java.lang.System.currentTimeMillis;

public class Time {
public static String timeSinceSeconds(int epochTimeInSeconds) {
public static CharSequence timeSinceSeconds(int epochTimeInSeconds) {
return timeSinceMS(epochTimeInSeconds*1000L);
}

public static String timeSinceMS(long epochTimeInMS) {
long ms = System.currentTimeMillis() - epochTimeInMS;
long sec = ms / 1000;
long min = sec / 60;
long hour = min / 60;
long day = hour / 24;
String end;
if (day > 0) {
if (day == 1) {
end = " day ago";
} else {
end = " days ago";
}
return (day + end);
}
if (hour > 0) {
if (hour == 1) {
end = " hour ago";
} else {
end = " hours ago";
}
return (hour + end);
}
if (min > 0) {
if (min == 1) {
end = " minute ago";
} else {
end = " minutes ago";
}
return (min + end);
}
if (sec == 1) {
end = " second ago";
} else {
end = " seconds ago";
}
return (sec + end);
public static CharSequence timeSinceMS(long epochTimeInMS) {
return DateUtils.getRelativeTimeSpanString(epochTimeInMS);
}
}

0 comments on commit 4a41b1d

Please sign in to comment.