Number s = canonicalDuration.getField(DatatypeConstants.SECONDS);
if (s == null)
{s = Integer.valueOf(0);}
//Copied from Saxon 8.6.1
final FastStringBuffer sb = new FastStringBuffer(32);
if (canonicalDuration.getSign() < 0) {
sb.append('-');
}
sb.append('P');
if (d != 0) {
sb.append(d + "D");
}
if ( d==0 || h!=0 || m!=0 || s.intValue() != 0) {
sb.append('T');
}
if (h != 0) {
sb.append(h + "H");
}
if (m != 0) {
sb.append(m + "M");
}
if ((s.intValue() != 0) || (d==0 && m==0 && h==0)) {
//TODO : ugly -> factorize
//sb.append(Integer.toString(s.intValue()));
//double ms = s.doubleValue() - s.intValue();
//if (ms != 0.0) {
// sb.append(".");
// sb.append(Double.toString(ms).substring(2));
//}
//0 is a dummy parameter
FloatingPointConverter.appendFloat(sb, s.floatValue()).getNormalizedString(0);
sb.append("S");
/*
if (micros == 0) {
sb.append(s + "S");
} else {
long ms = (s * 1000000) + micros;
String mss = ms + "";
if (s == 0) {
mss = "0000000" + mss;
mss = mss.substring(mss.length()-7);
}
sb.append(mss.substring(0, mss.length()-6));
sb.append('.');
int lastSigDigit = mss.length()-1;
while (mss.charAt(lastSigDigit) == '0') {
lastSigDigit--;
}
sb.append(mss.substring(mss.length()-6, lastSigDigit+1));
sb.append('S');
}
*/
}
//End of copy
return sb.toString();
}