Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global datetime formatter #143

Merged
merged 10 commits into from
Apr 1, 2019
Merged

Global datetime formatter #143

merged 10 commits into from
Apr 1, 2019

Conversation

ritikesh
Copy link
Collaborator

No description provided.

lib/blueprinter/configuration.rb Outdated Show resolved Hide resolved
lib/blueprinter/configuration.rb Outdated Show resolved Hide resolved
spec/integrations/shared/base_render_examples.rb Outdated Show resolved Hide resolved
order configs in ascending order
put back non-datetime field spec
Copy link
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
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.

let(:blueprint) do
Class.new(Blueprinter::Base) do
identifier :id
field :first_name, datetime_format: "%m/%d/%Y"
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
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
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.

end

def extract(field_name, object, local_options, options = {})
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
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
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
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