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
This commit is contained in:
lukemelia 2006-11-21 06:04:39 +00:00
parent fd67a7341e
commit 85486a6233
4 changed files with 11 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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? -%>