ruby-kit icon indicating copy to clipboard operation
ruby-kit copied to clipboard

Handle empty dates

Open zjwhitehead opened this issue 4 years ago • 5 comments

Currently when adding a date field to a template and calling a document that doesnt yet have that date filled out the SDK raises an error because it cant convert an empty string or nil to a Date/Time. It will still raise an error for malformed dates.

This fixes it by returning an empty text fragment (so calling .value) still works.

I thought about a few other approaches but this seems to have the lowest impact. Open to feedback

zjwhitehead avatar Jul 22 '21 17:07 zjwhitehead

Btw looks like these same tests that failed are failing in master

zjwhitehead avatar Jul 23 '21 22:07 zjwhitehead

What are your thoughts on this @faresd ?

zjwhitehead avatar Jul 29 '21 16:07 zjwhitehead

@alistairholt can you help here?

faresd avatar Oct 06 '21 09:10 faresd

@faresd sure. I'll take a look.

alistairholt avatar Oct 06 '21 13:10 alistairholt

@zjwhitehead thanks for your contribution and apologies for the massive delay in responding. While it works it feels slightly icky that we would return a Prismic::Fragments::Text instance when we are expecting a Prismic::Fragments::Date instance. I think it would be better if we adjust Prismic::Fragments::Date#to_html to simply do an early return with an empty string ('') if the value is nil.

alistairholt avatar Nov 13 '22 21:11 alistairholt