Skip to content

Global datetime formatter#143

Merged
mcclayton merged 10 commits intoprocore-oss:masterfrom
ritikesh:datetime_formatter
Apr 1, 2019
Merged

Global datetime formatter#143
mcclayton merged 10 commits intoprocore-oss:masterfrom
ritikesh:datetime_formatter

Conversation

@ritikesh
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/blueprinter/configuration.rb Outdated
Comment thread lib/blueprinter/configuration.rb Outdated
Comment thread spec/integrations/shared/base_render_examples.rb
order configs in ascending order
put back non-datetime field spec
Copy link
Copy Markdown
Contributor

@mcclayton mcclayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these changes! I’ll make the CHANGELOG updates at the time of the next release. Just want @philipqnguyen to get a chance to look at this and I’ll merge if these changes look good to him too 👍

Copy link
Copy Markdown
Contributor

@philipqnguyen philipqnguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!! We really needed this. I have some comments that I would like to be addressed or at least discussed about.

end
end
it('raises a BlueprinterError') { expect{subject}.to raise_error(Blueprinter::BlueprinterError) }
it('does not apply the date format') { should eq(result) }
Copy link
Copy Markdown
Contributor

@philipqnguyen philipqnguyen Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change. Previously we promised to raise an error if they passed an object with a datetime_format option that did not respond to #strftime, but now we are returning the original value.

if value.respond_to?(:strftime)
value = format_datetime(value, options)
end
value
Copy link
Copy Markdown
Contributor

@philipqnguyen philipqnguyen Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to alter the logic here a bit in order to prevent a breaking change.

  1. If options[:datetime_format] is explicitly passed and !value.respond_to?(:strftime), we should raise the original BlueprinterError.
  2. Otherwise, follow through with the rest of this logic.

extraction = extractor(object, options).extract(field_name, object, local_options, options)
value = options.key?(:datetime_format) ? format_datetime(extraction, options[:datetime_format]) : extraction

value = @datetime_formatter.extract(extraction, options)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to follow the current naming paradigm, how do you feel if we renamed DateTimeFormatter#extract to DateTimeFormatter#format? Since #extract makes more sense with the Extractor classes, but not so for this Formatter class.

Copy link
Copy Markdown
Contributor

@philipqnguyen philipqnguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes I requested @ritikesh . Looks good to me.

Copy link
Copy Markdown
Contributor

@mcclayton mcclayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better 💯

@mcclayton mcclayton merged commit 99bc36e into procore-oss:master Apr 1, 2019
@ritikesh ritikesh deleted the datetime_formatter branch August 12, 2019 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants