package com.brein.time.timer;

import java.util.concurrent.TimeUnit;

public class CountdownTimer {

    private final long timeIntervalInNanos;
    private final TimeUnit timeUnit;
    private long intervalStartInNanos = -1;

    /**
     * @param timeInterval Value of time units that the timer should be set to
     * @param timeUnit     Time unit of the time interval
     */
    public CountdownTimer(final long timeInterval,
                          final TimeUnit timeUnit) {
        this.timeIntervalInNanos = timeUnit.toNanos(timeInterval);
        this.timeUnit = timeUnit;
    }

    public void startTimer() {
        startTimer(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    public void startTimer(final long now,
                           final TimeUnit timeUnit) {
        intervalStartInNanos = timeUnit.toNanos(now);
    }

    public boolean timerEnded(final long now,
                              final TimeUnit timeUnit) {
        return intervalStartInNanos == -1 || timeUnit.toNanos(now) - intervalStartInNanos >= timeIntervalInNanos;
    }

    public long getRemainingTime(final long now,
                                 final TimeUnit timeUnit) {
        final long remainingNanos = timeUnit.toNanos(now) - intervalStartInNanos;
        return TimeUnit.NANOSECONDS.convert(remainingNanos, this.timeUnit);
    }
}

@@ -1084,149 +1084,582 @@
     
-public long getRemainingTime(final long now,%0A                                 final TimeUnit timeUnit) %7B%0A        final long remainingNanos = 
+/**%0A     * @param now      Current unix time%0A     * @param timeUnit Time unit that current time is given in%0A     *%0A     * @return Amount of time left on the timer, in the time unit that the timer was initialized with. If the timer%0A     * never started to begin with, or if the timer has ended, then return a 0.%0A     */%0A    public long getRemainingTime(final long now,%0A                                 final TimeUnit timeUnit) %7B%0A        if (intervalStartInNanos == -1) %7B%0A            return 0;%0A        %7D%0A%0A        final long remainingNanos = Math.max(0, timeIntervalInNanos - (
 time
@@ -1694,24 +1694,26 @@
 StartInNanos
+))
 ;%0A        re

fix to getremainingtime