Finding if a Joda Time Duration is 0 seconds long

Viewed 566

First, I'm required to use Java 7, so I can't use SE8 Time stuff sadly though I'd love to learn it instead!

I have a List of Duration as follows:

List<Duration> durations;

Most of these values are about 8 hours long, but some are zero (intentionally). How do I check if they are 0 days, 0 minutes, 0 seconds and 0 ms long? Do I need to check each method as follows or is there a neater method?

for(Duration duration : durations){
    if(duration.getStandardDays() == 0 && 
       duration.getStandardHours() == 0 && 
       duration.getStandardSeconds() == 0){
        //do something
    }
}

The reason I ask is I notice there's the constant ZERO in the API, and I assume this is somehow linked into it. How do I compare to it instead? Or should I?

https://www.joda.org/joda-time/apidocs/org/joda/time/Duration.html

3 Answers
Related