Skip to content

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