public static final void main(String[] args) {
TimeTicks t = new TimeTicks(100);
t.setValue(t.toString());
System.out.println(t.toLong());
}
The output we get is 6000.
The reason is that the setValue when no days exist has a “shift” in the usage of
private static final int[] FORMAT_FACTORS = { 246060100, 6060100, 60100, 100, 1 };
so i believe we should handle the FORMAT_FACTORS differently depending on whether the "days’ value exists on the string or not.
Thank you for reporting this bug. I have added a unit test for it and fixed it as follows in TimeTicks.setValue(String):
public final void setValue(String value) {
try {
long v = Long.parseLong(value);
setValue(v);
} catch (NumberFormatException nfe) {
long v = 0;
String[] num =
Arrays.stream(value.split("[days :,.]")).filter(x -> !x.isEmpty()).toArray(String[]::new);
int offset = FORMAT_FACTORS.length - num.length;
for (int i = FORMAT_FACTORS.length - offset - 1; i>=0; i--) {
if (num[i].length() > 0) {
long f = FORMAT_FACTORS[i+offset];
v += Long.parseLong(num[i]) * f;
}
}
setValue(v);
}
}
This fix will be included in SNMP4J 3.3.3 and 2.8.1.