Skip to content

Commit

Permalink
Merge pull request #2451 from prem-prakash/pp-fix-regex
Browse files Browse the repository at this point in the history
Fix regexp for converting rails date format to momentjs
  • Loading branch information
mshibuya committed Nov 2, 2015
2 parents 5daf6e9 + a668314 commit 8e9022a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/support/datetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def to_momentjs
'%y' => 'YY', # Year without a century (00..99)
}

strftime_format.gsub(/%\w/) { |match| translations[match] }
strftime_format.gsub(/\w[^.(!?%)\W]{1,}/, '[\0]').gsub(/%(\w|\-\w)/) { |match| translations[match] }
end

def parse_string(value)
Expand Down
18 changes: 18 additions & 0 deletions spec/rails_admin/support/datetime_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8

require 'spec_helper'

describe RailsAdmin::Support::Datetime do
describe 'to_momentjs' do
{
'%D de %M de %Y, %H:%M:%S' => 'MM/DD/YY [de] mm [de] YYYY, HH:mm:ss',
'%d/%-m/%Y, %H:%M:%S' => 'DD/M/YYYY, HH:mm:ss',
'%d de %B de %Y' => 'DD [de] MMMM [de] YYYY',
}.each do |strftime_format, momentjs_format|
it "convert strftime_format to momentjs_format - example #{strftime_format}" do
strftime_format = RailsAdmin::Support::Datetime.new(strftime_format)
expect(strftime_format.to_momentjs).to eq momentjs_format
end
end
end
end

0 comments on commit 8e9022a

Please sign in to comment.