felixbuenemann / xlsxtream

Streaming & Fast XLSX Spreadsheet Writer for Ruby
MIT License
217 stars 38 forks source link

Rescue gracefully from invalid dates #22

Closed sandstrom closed 6 years ago

sandstrom commented 6 years ago

For example, the string '2018-02-29' will match DATE_PATTERN but Date.parse will throw an ArgumentError when parsing the string.

Returning value instead yields the same result as a much more complicated regular expression would (regexps that takes leap years into account are needlessly complicated).

@felixbuenemann Let me know what you think!

felixbuenemann commented 6 years ago

Thanks, I think using rescue here is ok.

Can you add two tests test_text_invalid_date_column and test_text_invalid_date_time_column to test/xlsxtream/row_test.rb that exercises the new code?

There's no need to replicate all the different variants for date_time formats, a single example as for date should suffice.

felixbuenemann commented 6 years ago

@sandstrom Thanks for the contribution. I've added the two test mentioned above myself in 9159bc34692557899b21b63fac84cba3bda6429c.

I'll do a new patch release shortly.

sandstrom commented 6 years ago

@felixbuenemann Awesome! 😄

I did write down a todo-item to add the tests, but I've been busy with moving so I haven't had any spare time this past week.