From e4ce95c3a18496e8bc20787331d8f11c6b6b6e25 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 16 Nov 2007 20:26:36 +0000 Subject: [PATCH] Added a couple of new formats for the 'date format' setting. Added a 'time format' setting. git-svn-id: http://redmine.rubyforge.org/svn/trunk@905 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 10 ++++--- app/models/setting.rb | 17 ++++++++++++ app/views/projects/activity.rhtml | 2 +- app/views/settings/edit.rhtml | 5 +++- config/settings.yml | 7 +++-- lang/bg.yml | 1 + lang/cs.yml | 1 + lang/de.yml | 1 + lang/en.yml | 3 ++- lang/es.yml | 1 + lang/fr.yml | 3 ++- lang/he.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/nl.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 13 ++++----- lang/ru.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/zh.yml | 1 + test/unit/helpers/application_helper_test.rb | 28 ++++++++++++++++++++ 25 files changed, 86 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c03f073c1..e9ea74e2d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -71,15 +71,17 @@ module ApplicationHelper def format_date(date) return nil unless date - @date_format ||= (Setting.date_format.to_i == 0 ? l(:general_fmt_date) : "%Y-%m-%d") + # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed) + @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) date.strftime(@date_format) end - def format_time(time) + def format_time(time, include_date = true) return nil unless time - @date_format_setting ||= Setting.date_format.to_i time = time.to_time if time.is_a?(String) - @date_format_setting == 0 ? l_datetime(time) : (time.strftime("%Y-%m-%d") + ' ' + l_time(time)) + @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) + @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) + include_date ? time.strftime("#{@date_format} #{@time_format}") : time.strftime(@time_format) end def authoring(created, author) diff --git a/app/models/setting.rb b/app/models/setting.rb index 1c953f4c8..4d4cf0045 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -17,6 +17,23 @@ class Setting < ActiveRecord::Base + DATE_FORMATS = [ + '%Y-%m-%d', + '%d/%m/%Y', + '%d.%m.%Y', + '%d-%m-%Y', + '%m/%d/%Y', + '%d %b %Y', + '%d %B %Y', + '%b %d, %Y', + '%B %d, %Y' + ] + + TIME_FORMATS = [ + '%H:%M', + '%I:%M %p' + ] + cattr_accessor :available_settings @@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml")) Redmine::Plugin.registered_plugins.each do |id, plugin| diff --git a/app/views/projects/activity.rhtml b/app/views/projects/activity.rhtml index cc54eac95..c902d60a3 100644 --- a/app/views/projects/activity.rhtml +++ b/app/views/projects/activity.rhtml @@ -4,7 +4,7 @@

<%= day_name(day.cwday) %> <%= day.day %>