// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.tsp;

import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.tsp.Accuracy;

public class GenTimeAccuracy
{
    private Accuracy accuracy;
    
    public GenTimeAccuracy(final Accuracy accuracy) {
        this.accuracy = accuracy;
    }
    
    public int getSeconds() {
        return this.getTimeComponent(this.accuracy.getSeconds());
    }
    
    public int getMillis() {
        return this.getTimeComponent(this.accuracy.getMillis());
    }
    
    public int getMicros() {
        return this.getTimeComponent(this.accuracy.getMicros());
    }
    
    private int getTimeComponent(final ASN1Integer asn1Integer) {
        if (asn1Integer != null) {
            return asn1Integer.intValueExact();
        }
        return 0;
    }
    
    @Override
    public String toString() {
        return this.getSeconds() + "." + this.format(this.getMillis()) + this.format(this.getMicros());
    }
    
    private String format(final int i) {
        if (i < 10) {
            return "00" + i;
        }
        if (i < 100) {
            return "0" + i;
        }
        return Integer.toString(i);
    }
}
