cassava icon indicating copy to clipboard operation
cassava copied to clipboard

Difficult to implement ISO 8601 dates with current design

Open glutamate opened this issue 10 years ago • 1 comments

I am trying to output ISO 8601 dates surrounded by double quotes. This seems to be very difficult or impossible. What I want is this output:

followers,account_id,created
7346950,13460080,"2014-10-29T21:38:07.476015Z"

I tried this:

newtype IsoDate = IsoDate { unIsoDate :: UTCTime } deriving (Show, Eq, Ord)

instance CSV.ToField IsoDate where
  toField (IsoDate tm) = 
      fromString $ "\""++ (formatTime defaultTimeLocale "%FT%T%QZ" tm)++"\""

But that gives me triple double-quotes around the date. Is there any way to specify that a field must always be surrounded by quotes?

glutamate avatar Oct 29 '14 22:10 glutamate

I have some ideas for how we could support this. To better understand the problem, why do you want to do this? The CSV spec doesn't required it, although many programs are not conforming so I'm guessing that's why you need the extra quotes.

tibbe avatar Nov 04 '14 09:11 tibbe