public string toIso()
{
StringBuilder s = new StringBuilder();
long ticks = this.m_ticks;
if (ticks == 0) return "PT0S";
if (ticks < 0) s.Append('-');
s.Append('P');
long abs = ticks < 0 ? -ticks : ticks;
long sec = abs / nsPerSec;
long frac = abs % nsPerSec;
// days
if (sec > secPerDay) { s.Append(sec/secPerDay).Append('D'); sec = sec % secPerDay; }
if (sec == 0 && frac == 0) return s.ToString();
s.Append('T');
// hours, minutes
if (sec > secPerHr) { s.Append(sec/secPerHr).Append('H'); sec = sec % secPerHr; }
if (sec > secPerMin) { s.Append(sec/secPerMin).Append('M'); sec = sec % secPerMin; }
if (sec == 0 && frac == 0) return s.ToString();
// seconds and fractional seconds
s.Append(sec);
if (frac != 0)
{
s.Append('.');
for (int i=10; i<=100000000; i*=10) if (frac < i) s.Append('0');
s.Append(frac);
while (s[s.Length-1] == '0') s.Length = s.Length -1;
}
s.Append('S');
return s.ToString();
}