summaryrefslogtreecommitdiffstats
path: root/app/models/import.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-08-14 15:42:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-08-14 15:42:28 +0000
commit722eaed7216270d8e89f50c92abb1cfaf9bf1503 (patch)
tree17c0bbc3ffe492d4bdb1e2154f158afac46bee43 /app/models/import.rb
parentfe24da53e7841fdb76651c8fa3abd561fa97cf7f (diff)
downloadredmine-722eaed7216270d8e89f50c92abb1cfaf9bf1503.tar.gz
redmine-722eaed7216270d8e89f50c92abb1cfaf9bf1503.zip
Adds support for custom date format when importing a CSV file (#950).
git-svn-id: http://svn.redmine.org/redmine/trunk@14495 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/import.rb')
-rw-r--r--app/models/import.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/import.rb b/app/models/import.rb
index b7064d932..df29d1788 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -27,6 +27,14 @@ class Import < ActiveRecord::Base
validates_presence_of :filename, :user_id
validates_length_of :filename, :maximum => 255
+ DATE_FORMATS = [
+ '%Y-%m-%d',
+ '%d/%m/%Y',
+ '%m/%d/%Y',
+ '%d.%m.%Y',
+ '%d-%m-%Y'
+ ]
+
def initialize(*args)
super
self.settings ||= {}
@@ -201,6 +209,14 @@ class Import < ActiveRecord::Base
end
end
+ def row_date(row, key)
+ if s = row_value(row, key)
+ format = settings['date_format']
+ format = DATE_FORMATS.first unless DATE_FORMATS.include?(format)
+ Date.strptime(s, format) rescue s
+ end
+ end
+
# Builds a record for the given row and returns it
# To be implemented by subclasses
def build_object(row)