Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method get age in ms for Message class #1296

Open
wants to merge 1 commit into
base: 2.4
Choose a base branch
from

Conversation

apirom9
Copy link

@apirom9 apirom9 commented Oct 13, 2017

add method get age in ms for Message class

@thboileau thboileau self-assigned this Oct 20, 2017
@thboileau thboileau force-pushed the 2.4 branch 4 times, most recently from 660ec16 to 423c818 Compare October 26, 2017 20:23
@Tembrel
Copy link
Collaborator

Tembrel commented Jan 30, 2018

Does this really carry its weight? If so, how about:

  public long getAge(TimeUnit unit) {
      Date date = getDate();
      if (date == null) {
          return Long.MIN_VALUE; // Long.MAX_VALUE?
      } else {
          long ageMillis = System.currentTimeMillis() - date.getTime();
          return unit.convert(ageMillis, TimeUnit.MILLISECONDS);
      }
  }

You want to be able to distinguish the case of the age being 0 from the case where there is no date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants