01: package org.bouncycastle.tsp;
02:
03: import java.text.DecimalFormat;
04:
05: import org.bouncycastle.asn1.DERInteger;
06: import org.bouncycastle.asn1.tsp.Accuracy;
07:
08: public class GenTimeAccuracy {
09: private Accuracy accuracy;
10:
11: public GenTimeAccuracy(Accuracy accuracy) {
12: this .accuracy = accuracy;
13: }
14:
15: public int getSeconds() {
16: return getTimeComponent(accuracy.getSeconds());
17: }
18:
19: public int getMillis() {
20: return getTimeComponent(accuracy.getMillis());
21: }
22:
23: public int getMicros() {
24: return getTimeComponent(accuracy.getMicros());
25: }
26:
27: private int getTimeComponent(DERInteger time) {
28: if (time != null) {
29: return time.getValue().intValue();
30: }
31:
32: return 0;
33: }
34:
35: public String toString() {
36: DecimalFormat formatter = new DecimalFormat("000"); // three integer
37: // digits
38: return getSeconds() + "." + formatter.format(getMillis())
39: + formatter.format(getMicros());
40: }
41: }
|