chathurahettiarachchi / timeago Goto Github PK
View Code? Open in Web Editor NEWThis will help to get how much time have passed. Useful in showing messages, notifications time and etc.
License: Apache License 2.0
This will help to get how much time have passed. Useful in showing messages, notifications time and etc.
License: Apache License 2.0
Hello, I am getting this error after attempting to import the project by adding "Implementation 'com.chootdev.timezago:1.1.8' into my app level gradle file: ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform artifact 'timezago.aar (com.chootdev:timezago:1.1.8)' to match attributes {artifactType=jar} I have not found any information regarding this error online. Clicking on "Show details" doesn't work. Do any of you know what the problem is?
You're checking whether the context is null and then still continue to make use of it even though it is null.
public String getTimeAgo(Date startDate) {
// date counting is done till todays date
Date endDate = dateTimeNow;
// time difference in milli seconds
long different = endDate.getTime() - startDate.getTime();
if (context==null) {
if (different < MINUTE_MILLIS) {
return context.getResources().getString(R.string.just_now);
} else if (different < 2 * MINUTE_MILLIS) {
return context.getResources().getString(R.string.a_min_ago);
} else if (different < 50 * MINUTE_MILLIS) {
return different / MINUTE_MILLIS + context.getString(R.string.mins_ago);
} else if (different < 90 * MINUTE_MILLIS) {
return context.getString(R.string.a_hour_ago);
} else if (different < 24 * HOUR_MILLIS) {
timeFromData = timeFormat.format(startDate);
return timeFromData;
} else if (different < 48 * HOUR_MILLIS) {
return context.getString(R.string.yesterday);
} else if (different < 7 * DAY_MILLIS) {
return different / DAY_MILLIS + context.getString(R.string.days_ago);
} else if (different < 2 * WEEKS_MILLIS) {
return different / WEEKS_MILLIS + context.getString(R.string.week_ago);
} else if (different < 3.5 * WEEKS_MILLIS) {
return different / WEEKS_MILLIS + context.getString(R.string.weeks_ago);
} else {
pastDate = dateFormat.format(startDate);
return pastDate;
}
} else {
if (different < MINUTE_MILLIS) {
return context.getResources().getString(R.string.just_now);
} else if (different < 2 * MINUTE_MILLIS) {
return context.getResources().getString(R.string.a_min_ago);
} else if (different < 50 * MINUTE_MILLIS) {
return different / MINUTE_MILLIS + context.getString(R.string.mins_ago);
} else if (different < 90 * MINUTE_MILLIS) {
return context.getString(R.string.a_hour_ago);
} else if (different < 24 * HOUR_MILLIS) {
timeFromData = timeFormat.format(startDate);
return timeFromData;
} else if (different < 48 * HOUR_MILLIS) {
return context.getString(R.string.yesterday);
} else if (different < 7 * DAY_MILLIS) {
return different / DAY_MILLIS + context.getString(R.string.days_ago);
} else if (different < 2 * WEEKS_MILLIS) {
return different / WEEKS_MILLIS + context.getString(R.string.week_ago);
} else if (different < 3.5 * WEEKS_MILLIS) {
return different / WEEKS_MILLIS + context.getString(R.string.weeks_ago);
} else {
pastDate = dateFormat.format(startDate);
return pastDate;
}
}
}
I took the liberty to report the issue but otherwise I had since switched to PrettyTime
You can use DateUtils.getRelativeTimeSpanString() directly, with i18n and without any extra dependency.
Better to use formatting in strings https://developer.android.com/reference/java/util/Formatter.html
Right now
1 minute ago
5 minutes ago
1 hour ago
5 hours ago
Yesterday
2 days ago
1 week ago
Two weeks ago
In spanish
Ahora mismo
"Hace 1 minuto
Hace 5 minutos
Hace 1 hora
Hace 5 horas
Ayer
Hace 2 días
Hace 1 semana
Hace 2 semanas
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getString(int)' on a null object reference
at com.choota.dev.ctimeago.TimeAgo.getTimeAgo(TimeAgo.java:77)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.