Closed fumieval closed 1 year ago
I wish time package had a way to specify the number of decimal places...
This is possible using a <width>
modifier (see the Data.Time.Format
documentation). For example:
ghci> let timeFormat = "%Y-%m-%dT%H:%M:%S%6QZ"
ghci> formatTime defaultTimeLocale timeFormat $ UTCTime (toEnum 0) (picosecondsToDiffTime 1)
"1858-11-17T00:00:00.000000Z"
The key point is the %6Q
part which specifies that we want the decimal point and fraction of second, truncated to at most 6 digits. The documentation is not great here and only talks about "padding", but when the specified width is smaller than the actual length of the value, then this modifier will also truncate the string.
That's good to know. I updated the code to use %Y-%m-%dT%H:%M:%S%6QZ
Checklist
@since
annotations.I drew a conclusion too early when I saw
iso8601Show <$> getCurrentTime
showing 6 decimal places... I realised that it may still show more decimal places if depending on the environment, causing parse errors on AzureAD.This change circumvents the problem by truncating the timestamp to 26 characters and appending 'Z'. I wish
time
package had a way to specify the number of decimal places...