From 0ee77ff7990819e504e33bce699e657f6b27be72 Mon Sep 17 00:00:00 2001 From: Prem Prakash Date: Sat, 31 Oct 2015 20:26:17 -0200 Subject: [PATCH 1/5] fix regexp for converting rails date format to momentjs --- lib/rails_admin/support/datetime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rails_admin/support/datetime.rb b/lib/rails_admin/support/datetime.rb index 2138790ad6..f688b9f211 100644 --- a/lib/rails_admin/support/datetime.rb +++ b/lib/rails_admin/support/datetime.rb @@ -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[^\.(!?%)\s$]/, '[\0]').gsub(/%\w/) { |match| translations[match] } end def parse_string(value) From b693251503c63b094b095fd8697c8ea24602af37 Mon Sep 17 00:00:00 2001 From: Prem Prakash Date: Sun, 1 Nov 2015 00:37:23 -0200 Subject: [PATCH 2/5] refactor regexs --- lib/rails_admin/support/datetime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rails_admin/support/datetime.rb b/lib/rails_admin/support/datetime.rb index f688b9f211..cb3d22c891 100644 --- a/lib/rails_admin/support/datetime.rb +++ b/lib/rails_admin/support/datetime.rb @@ -72,7 +72,7 @@ def to_momentjs '%y' => 'YY', # Year without a century (00..99) } - strftime_format.gsub(/\w[^\.(!?%)\s$]/, '[\0]').gsub(/%\w/) { |match| translations[match] } + strftime_format.gsub(/\w[^.(!?%)\s]{1,}/, '[\0]').gsub(/%(\w|\-\w)/) { |match| translations[match] } end def parse_string(value) From b5f71a6e8daaad71ed548878c14fef4c2e950d2a Mon Sep 17 00:00:00 2001 From: Prem Prakash Date: Sun, 1 Nov 2015 00:48:20 -0200 Subject: [PATCH 3/5] fix regexp --- lib/rails_admin/support/datetime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rails_admin/support/datetime.rb b/lib/rails_admin/support/datetime.rb index cb3d22c891..7cbdeee4d4 100644 --- a/lib/rails_admin/support/datetime.rb +++ b/lib/rails_admin/support/datetime.rb @@ -72,7 +72,7 @@ def to_momentjs '%y' => 'YY', # Year without a century (00..99) } - strftime_format.gsub(/\w[^.(!?%)\s]{1,}/, '[\0]').gsub(/%(\w|\-\w)/) { |match| translations[match] } + strftime_format.gsub(/\w[^.(!?%)\W]{1,}/, '[\0]').gsub(/%(\w|\-\w)/) { |match| translations[match] } end def parse_string(value) From 81f014e177e6d90656dea15bc9cd7c20f4fc658e Mon Sep 17 00:00:00 2001 From: Prem Prakash Date: Sun, 1 Nov 2015 11:49:39 -0200 Subject: [PATCH 4/5] add spec --- spec/rails_admin/support/datetime_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spec/rails_admin/support/datetime_spec.rb diff --git a/spec/rails_admin/support/datetime_spec.rb b/spec/rails_admin/support/datetime_spec.rb new file mode 100644 index 0000000000..0deceefe49 --- /dev/null +++ b/spec/rails_admin/support/datetime_spec.rb @@ -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 From a6683141b4ed17679d44c29da62b8780133a4d57 Mon Sep 17 00:00:00 2001 From: Prem Prakash Date: Sun, 1 Nov 2015 17:52:21 -0200 Subject: [PATCH 5/5] fix rubocop --- spec/rails_admin/support/datetime_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_admin/support/datetime_spec.rb b/spec/rails_admin/support/datetime_spec.rb index 0deceefe49..8965551a64 100644 --- a/spec/rails_admin/support/datetime_spec.rb +++ b/spec/rails_admin/support/datetime_spec.rb @@ -7,7 +7,7 @@ { '%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' + '%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)