summaryrefslogtreecommitdiffstats
path: root/app/models
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
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')
-rw-r--r--app/models/import.rb16
-rw-r--r--app/models/issue_import.rb12
2 files changed, 25 insertions, 3 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)
diff --git a/app/models/issue_import.rb b/app/models/issue_import.rb
index 2ff127605..7a7cf1e83 100644
--- a/app/models/issue_import.rb
+++ b/app/models/issue_import.rb
@@ -122,10 +122,10 @@ class IssueImport < Import
attributes['parent_issue_id'] = parent_issue_id
end
end
- if start_date = row_value(row, 'start_date')
+ if start_date = row_date(row, 'start_date')
attributes['start_date'] = start_date
end
- if due_date = row_value(row, 'due_date')
+ if due_date = row_date(row, 'due_date')
attributes['due_date'] = due_date
end
if done_ratio = row_value(row, 'done_ratio')
@@ -133,7 +133,13 @@ class IssueImport < Import
end
attributes['custom_field_values'] = issue.custom_field_values.inject({}) do |h, v|
- if value = row_value(row, "cf_#{v.custom_field.id}")
+ value = case v.custom_field.field_format
+ when 'date'
+ row_date(row, "cf_#{v.custom_field.id}")
+ else
+ row_value(row, "cf_#{v.custom_field.id}")
+ end
+ if value
h[v.custom_field.id.to_s] = v.custom_field.value_from_keyword(value, issue)
end
h