mineschan/MZTimerLabel

Day counter problem for MZTimerLabelTypeTimer

Closed this issue · 1 comments

Hello,

I want to use this wonderful timer to display seconds, minutes, hours and days remaining.
Unfortunately, the day value is incorrect (there is always an extra one day displayed).
Is there a workaround to get this working properly ?

Here is my code :
@IBOutlet weak var timer1: MZTimerLabel!
let interval = NSTimeInterval(8) // 8 seconds
timer1.setCountDownTime(interval)
timer1.timeFormat = "dd-HH-mm-ss"
timer1.start()
// displays 01-00-00-08 instead of 00-00-00-08

Thank you !

- (NSString*)timerLabel:(MZTimerLabel *)timerLabel customTextToDisplayAtTime:(NSTimeInterval)time{
    int second = (int)time  % 60;
    int minute = ((int)time / 60) % 60;
    int hours = ((int)time / 3600) % 24;
    int days = time / (3600 * 24);

    if (days > 0) {
        return [NSString stringWithFormat:@"%d : %02d : %02d : %02d",days,hours,minute,second];

    }  else if (hours > 0) {
        return [NSString stringWithFormat:@"%d : %02d : %02d",hours,minute,second];

    } else if (minute > 0) {
        return [NSString stringWithFormat:@"%d : %02d",minute,second];

    } else if (second > 0) {
        return [NSString stringWithFormat:@"%02d",second];

    } else {
        return nil;
    }
}