How do you use Ruby CSV converters?

前端 未结 3 801
耶瑟儿~
耶瑟儿~ 2021-02-07 13:48

Suppose you have the following file:

textfield,datetimefield,numfield
foo,2008-07-01 17:50:55.004688,1
bar,2008-07-02 17:50:55.004688,2

The Rub

3条回答
  •  轮回少年
    2021-02-07 14:43

    Your date times don't match the CSV::DateTimeMatcher regexp that CSV uses to decide whether it should attempt a date time conversion. By the looks of it it's doing so because of the fractional seconds you've got.

    You could either overwrite that constant or write your own converter (DateTime.parse seems happy with your strings)

提交回复
热议问题