From 85486a6233290a9a76dcfe30709416152f44a1cc Mon Sep 17 00:00:00 2001 From: lukemelia Date: Tue, 21 Nov 2006 06:04:39 +0000 Subject: [PATCH] Fixes #403 "When prefs are set to date formats other than %m-%d-%y, database errors are produced on save." This bug was due to the Chronic library integration, which I commented out for now. In its youthful state, Chronic has a U.S.-centered worldview with only limited support for non-U.S. date formats. In particular, its tests show that it can support parsing 5/27/1979 and 27/5/1979 but are silent on the more challenging case of 12/11/2006 or 11/12/2006. I see no way to configure the plugin with date format. Without that, all users would have to use the (admittedly awkward) U.S. date format. Maybe we could prefer a successful format-respecting date parse and fall back to a Chronic parse? I also updated the "action due"" text on deferred items to use the user's date format. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@358 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 5 +++-- tracks/app/controllers/todo_controller.rb | 6 ++++++ tracks/app/models/todo.rb | 2 +- tracks/app/views/todo/_item.rhtml | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index 089c1797..bd8eb08e 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -78,8 +78,9 @@ class ApplicationController < ActionController::Base end def parse_date_per_user_prefs( s ) - return nil if s == '' - Chronic.parse(s).to_date + return nil if s.blank? + Date.strptime(s, @user.preference.date_format) + #Chronic.parse(s).to_date end def init_data_for_sidebar diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index a6cd93d6..86f04bd1 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -175,11 +175,17 @@ class TodoController < ApplicationController end params["item"]["context_id"] = context.id end + if params["item"].has_key?("due") params["item"]["due"] = parse_date_per_user_prefs(params["item"]["due"]) else params["item"]["due"] = "" end + + if params['item']['show_from'] + params['item']['show_from'] = parse_date_per_user_prefs(params['item']['show_from']) + end + @saved = @item.update_attributes params["item"] @context_changed = @original_item_context_id != @item.context_id if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todos.length; end diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 7d3f5ade..2f9fd629 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -45,7 +45,7 @@ class Todo < ActiveRecord::Base validates_presence_of :context def validate - if deferred? && show_from != nil && show_from < Date.today() + if deferred? && !show_from.blank? && show_from < Date.today() errors.add("Show From", "must be a date in the future.") end end diff --git a/tracks/app/views/todo/_item.rhtml b/tracks/app/views/todo/_item.rhtml index 8d9ca70f..410d2451 100644 --- a/tracks/app/views/todo/_item.rhtml +++ b/tracks/app/views/todo/_item.rhtml @@ -20,7 +20,7 @@ <%= sanitize(item.description) %> <% if item.deferred? && item.due -%> - (action due on <%= item.due.to_s %>) + (action due on <%= format_date(item.due) %>) <% end -%> <% if item.completed? -%>