You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on a ASN.1 DER serializer. This standard has support for sub-second representation, but they (foolishly) drop significant zeros in their representation.
I currently use
letmut time = format!("{}", time.format("%Y%m%d%H%M%S%f"));let(prefix, fraction) = time.split_at_mut(14);let time = match fraction.as_bytes().iter().enumerate().rfind(|&(_,&x)| x != b'0'){Some((offset, _)) => prefix.to_owned() + "." + &fraction[0..offset+1] + "Z",None => prefix.to_owned() + "Z",};
to generate my output (which is both ugly and inefficient). What it basically does is it prints out the "%f" (nanoseconds) and truncates its zeroes. If there's nothing left, the "." is also omitted.
TL;DR: So: I basically wonder whether it'd be possible for a (preferably more efficient) "%S" like formatter that outputs the seconds, and omits zeroes and the "." when "possible".