Skip to content

Commit

Permalink
Merge pull request #2547 from ivanzotov/fix_delocalize
Browse files Browse the repository at this point in the history
Fix delocalize strftime_format for DateTime.strptime to support minus
  • Loading branch information
bbenezech committed Feb 4, 2016
2 parents d0d5a0c + 08c8c69 commit 10c6ba6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rails_admin/support/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def parse_string(value)

begin
# Adjust with the correct timezone and daylight savint time
datetime_with_wrong_tz = ::DateTime.strptime(delocalized_value, strftime_format)
datetime_with_wrong_tz = ::DateTime.strptime(delocalized_value, strftime_format.gsub('%-d', '%d'))
Time.zone.parse(datetime_with_wrong_tz.strftime('%Y-%m-%d %H:%M:%S'))
rescue ArgumentError
nil
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_admin/config/fields/types/datetime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
Time.zone = 'UTC'
end

it 'is able to read %B %d, %Y %H:%M' do
it 'is able to read %B %-d, %Y %H:%M' do
@object = FactoryGirl.create(:field_test)
@object.datetime_field = field.parse_input(datetime_field: @time.strftime('%B %d, %Y %H:%M'))
@object.datetime_field = field.parse_input(datetime_field: @time.strftime('%B %-d, %Y %H:%M'))
expect(@object.datetime_field.strftime('%Y-%m-%d %H:%M')).to eq(@time.strftime('%Y-%m-%d %H:%M'))
end

Expand Down

0 comments on commit 10c6ba6

Please sign in to comment.