MCPcopy Index your code
hub / github.com/damien5314/TimeSinceTextView

github.com/damien5314/TimeSinceTextView @1.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.3 ↗ · + Follow
35 symbols 146 edges 4 files 5 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TimeSinceTextView

This is a subclass of android.widget.TextView that exposes a method setDate() which accepts a long Unix timestamp or java.util.Date. The view converts the date into a String which describes the date in terms of time since that timestamp. For example, if the current timestamp is Unix 1453503166 and we call timeSinceTextView.setDate(1453503116), "50 seconds ago" is displayed.

Changelog

Javadoc

Comparison to DateUtils.getRelativeTimeSpanString

I actually wrote this library before I knew about DateUtils.getRelativeTimeSpanString, but the output is actually quite a bit different. The DateUtils implementation should return localized text and allows for customizable flags. See here for a comparison of the output of different time stamps.

Usage

Simply declare a TimeSinceTextView in XML or create one in code.

<com.ddiehl.timesincetextview.TimeSinceTextView
  android:id="@+id/timestamp"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />

Then call setDate(Date) or setDate(long) with a Unix timestamp, and the text will be automatically generated and set to the view.

((TimeSinceTextView) findViewById(R.id.timestamp)).setDate(1452827942);

To get an abbreviated form of the converted text, add app:abbreviated="true" to your XML layout.

<com.ddiehl.timesincetextview.TimeSinceTextView
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:tstv_abbreviated="true" />

The class TimeSince also contains static methods which can be used to retrieve a relative timestamp string without an instance of TimeSinceTextView.

Add to your project

Release

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
  compile 'com.github.damien5314:TimeSinceTextView:1.+'
}

Screenshot

Contributions

Pull requests are welcome, in particular in would be nice to have strings.xml translated into as many languages as possible.

Core symbols most depended-on inside this repo

getFormattedDateString
called by 26
library/src/main/java/com/ddiehl/timesincetextview/TimeSince.java
setDate
called by 17
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java
findView
called by 15
sample/src/main/java/com/ddiehl/timesincetextview/sample/MainActivity.java
init
called by 4
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java
TimeSince
called by 0
library/src/main/java/com/ddiehl/timesincetextview/TimeSince.java
TimeSinceTextView
called by 0
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java
getDate
called by 0
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java
isAbbreviated
called by 0
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java

Shape

Method 31
Class 4

Languages

Java100%

Modules by API surface

library/src/androidTest/java/com/ddiehl/timesincetextview/TimeSinceTextViewAndroidTest.java22 symbols
library/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java7 symbols
sample/src/main/java/com/ddiehl/timesincetextview/sample/MainActivity.java3 symbols
library/src/main/java/com/ddiehl/timesincetextview/TimeSince.java3 symbols

For agents

$ claude mcp add TimeSinceTextView \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact