Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
damien5314 committed Jan 26, 2016
1 parent d8f1669 commit 392c1b1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Comparison.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Output of `DateUtils.getRelativeTimeSpanString(long)` vs `TimeSinceTextView.getFormattedDateString(long, ...)`

| Time Since | DateUtils | TimeSinceTextView |
| ----------------------- | -------------- | ----------------- |
| 10s ago | 0 minutes ago | just now |
| 11s ago | 0 minutes ago | 11 seconds ago |
| 59s ago | 0 minutes ago | 59 seconds ago |
| 60s ago | 1 minute ago | 1 minute ago |
| 59m, 59s ago | 59 minutes ago | 59 minutes ago |
| 60m ago | 1 hour ago | 1 hour ago |
| 23h, 59m, 59s ago | 23 hours ago | 23 hours ago |
| 24h ago | Yesterday | 1 day ago |
| 6d, 23h, 59m, 59s ago | 7 days ago | 6 days ago |
| 7d ago | Jan 18, 2016 | 1 week ago |
| 29d, 23h, 59m, 59s ago | Dec 26, 2015 | 4 weeks ago |
| 30d ago | Dec 26, 2015 | 1 month ago |
| 364d, 23h, 59m, 59s ago | Jan 25, 2015 | 12 months ago |
| 365d ago | Jan 25, 2015 | 1 year ago |
| 30yr ago | Feb 1, 1986 | 30 years ago |
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# TimeSinceTextView

This is a subclass of android.widget.TextView which exposes a method `setDate()` which can take either a Unix timestamp (`long`) or `java.util.Date`. The view converts the date into a String which describes the date in terms of time since.

e.g. If the current timestamp is Unix 1453503166 and the time passed to `setDate()` is 1453503116, "50 seconds ago" is displayed.
e.g. If the current timestamp is Unix 1453503166 and we call `timeSinceTextView.setDate(1453503116)`, "50 seconds ago" is displayed.

## Comparison to DateUtils.getRelativeTimeSpanString

I actually wrote this library before I knew about [DateUtils.getRelativeTimeSpanString](http://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeDateTimeString), but the output is actually quite a bit different. The DateUtils implementation should return localized text and allows for customizable flags. See [here](Comparison.md) for a comparison of the output of different time stamps.

## Usage

Expand Down Expand Up @@ -46,6 +51,7 @@ as well as the dependency in your module build.gradle file.


## Screenshot

![Screenshot](/screenshots/1453502946.png)

## Contributions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void getFormattedDateString_now() {
}

@Test
public void getFormattedDateString_10seconds() {
public void getFormattedDateString_11seconds() {
assertThat(
TimeSinceTextView.getFormattedDateString(
mTime - 11, mTime, false, mContext),
Expand Down

0 comments on commit 392c1b1

Please sign in to comment.