Giter Site home page Giter Site logo

chathurahettiarachchi / timeago Goto Github PK

View Code? Open in Web Editor NEW
169.0 9.0 33.0 149 KB

This will help to get how much time have passed. Useful in showing messages, notifications time and etc.

License: Apache License 2.0

Java 100.00%
timeago notifications android-library

timeago's Introduction

TimeAgo Download

I know what is mostly experianced problem when doing my development. So I decide to write this library to get how much time passed. Many of us having problem how to show how much time have passed, how to show it like in messages, notifications... Yeah, you looking at the right place. This will fix your issue.

logo

####Let's take a look how to add this to your project

For the android project just include the following dependency inside you buil.gradle's depedency list.

Gradle

repositories {
  jcenter()
}

dependencies {
    ...
    compile 'com.chootdev:timezago:1.1.8'
}

if you using maven use following Maven

<dependency>
  <groupId>com.chootdev</groupId>
  <artifactId>timezago</artifactId>
  <version>1.1.8</version>
  <type>pom</type>
</dependency>

After setup installing lib to your project you just need only to calls it using just two lines of code. It will return you a string with the resuls.

Usage

TimeAgo timeAgo = new TimeAgo();
String result = timeAgo.getTimeAgo(YOUR_PAST_DATE);
TimeAgo timeAgo = new TimeAgo().locale(CONTEXT).with(CUSTOM_DATE_FORMAT);
String result = timeAgo.getTimeAgo(YOUR_CUSTOM_PAST_DATE);

Limitations

  • Currently not supporting for custom date formats. supports for ISO foramt and dd/MM/yyyy HH:mm:ss only.
  • Some parts like reducing time from your input date need to manage by you, and i was planning to add those line in future too.

Output patterns

  • Below 1min - Right now
  • 1min - 1h - returns like 20 minutes
  • 1h - 24h - time eg: 12.34pm
  • 1d - 1w - 1 week ago
  • 1w - 4w - 1 week ago, 2 weeks ago 3 weeks ago
  • 1m > - date

Screenshot

src

Changelog

  • 1.1.8
    • Format changes
  • 1.1.7
    • Added ru localization, changed min API from 16 to 9, custom date format
  • 1.1.6
    • Fixed grammer issues
  • 1.1.5
    • Stable the release
  • 1.1.0
    • Fixed crashing for ISO date format
  • 1.0.0
    • Initial release

Author

Chathura Hettiarachchi, [email protected]

Checkout my other contributions, https://github.com/ChathuraHettiarachchi?tab=repositories

License

Copyright 2016 Chathura Hettiarachchi

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

timeago's People

Contributors

pomis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timeago's Issues

NullPointerException in TimeAgo.java (1.1.8)

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

Falied to transform artifact

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.