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
This commit is contained in:
Jean-Philippe Lang 2007-11-16 20:26:36 +00:00
parent 4951676172
commit e4ce95c3a1
25 changed files with 86 additions and 18 deletions

View File

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

View File

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

View File

@ -4,7 +4,7 @@
<h3><%= day_name(day.cwday) %> <%= day.day %></h3>
<ul>
<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
<li><p><%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
<li><p><%= format_time(e.event_datetime, false) %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
<% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
<span class="author"><%= e.event_author if e.respond_to?(:event_author) %></span></p></li>
<% end %>

View File

@ -20,7 +20,10 @@
<%= select_tag 'settings[default_language]', options_for_select( lang_options_for_select(false), Setting.default_language) %></p>
<p><label><%= l(:setting_date_format) %></label>
<%= select_tag 'settings[date_format]', options_for_select( [[l(:label_language_based), '0'], ['ISO 8601 (YYYY-MM-DD)', '1']], Setting.date_format) %></p>
<%= select_tag 'settings[date_format]', options_for_select( [[l(:label_language_based), '']] + Setting::DATE_FORMATS.collect {|f| [Date.today.strftime(f), f]}, Setting.date_format) %></p>
<p><label><%= l(:setting_time_format) %></label>
<%= select_tag 'settings[time_format]', options_for_select( [[l(:label_language_based), '']] + Setting::TIME_FORMATS.collect {|f| [Time.now.strftime(f), f]}, Setting.time_format) %></p>
<p><label><%= l(:setting_attachment_max_size) %></label>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB</p>

View File

@ -71,11 +71,10 @@ autologin:
format: int
default: 0
# date format
# 0: language based
# 1: ISO format
date_format:
format: int
default: 0
default: ''
time_format:
default: ''
cross_project_issue_relations:
default: 0
notified_events:

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -186,6 +186,7 @@ setting_commit_ref_keywords: Referencing keywords
setting_commit_fix_keywords: Fixing keywords
setting_autologin: Autologin
setting_date_format: Date format
setting_time_format: Time format
setting_cross_project_issue_relations: Allow cross-project issue relations
setting_issue_list_default_columns: Default columns displayed on the issue list
setting_repositories_encodings: Repositories encodings
@ -425,7 +426,7 @@ label_month: Month
label_week: Week
label_date_from: From
label_date_to: To
label_language_based: Language based
label_language_based: Based on user's language
label_sort_by: Sort by %s
label_send_test_email: Send a test email
label_feeds_access_key_created_on: RSS access key created %s ago

View File

@ -540,3 +540,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -186,6 +186,7 @@ setting_commit_ref_keywords: Mot-clés de référencement
setting_commit_fix_keywords: Mot-clés de résolution
setting_autologin: Autologin
setting_date_format: Format de date
setting_time_format: Format d'heure
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets
setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes
setting_repositories_encodings: Encodages des dépôts
@ -425,7 +426,7 @@ label_month: Mois
label_week: Semaine
label_date_from: Du
label_date_to: Au
label_language_based: Basé sur la langue
label_language_based: Basé sur la langue de l'utilisateur
label_sort_by: Trier par %s
label_send_test_email: Envoyer un email de test
label_feeds_access_key_created_on: Clé d'accès RSS créée il y a %s

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -538,3 +538,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ label_nobody: nobody
setting_protocol: Protocol
mail_body_account_information: Your Redmine account information
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -538,3 +538,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: Możesz użyć twojego "%s" konta do zal
mail_body_account_information: Twoje konto w Redmine
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -38,10 +38,10 @@ activerecord_error_circular_dependency: Aceasta relatie ar crea dependenta circu
general_fmt_age: %d an
general_fmt_age_plural: %d ani
general_fmt_date: %%m/%%d/%%A
general_fmt_datetime: %%m/%%d/%%A %%Z:%%L %%p
general_fmt_datetime_short: %%b %%d, %%Z:%%L %%p
general_fmt_time: %%Z:%%L %%p
general_fmt_date: %%m/%%d/%%Y
general_fmt_datetime: %%m/%%d/%%Y %%I:%%M %%p
general_fmt_datetime_short: %%b %%d, %%I:%%M %%p
general_fmt_time: %%I:%%M %%p
general_text_No: 'Nu'
general_text_Yes: 'Da'
general_text_no: 'nu'
@ -74,9 +74,9 @@ notice_email_sent: Un e-mail a fost trimis la adresa %s
notice_email_error: Eroare in trimiterea e-mailului (%s)
notice_feeds_access_key_reseted: Parola de acces RSS a fost resetat.
mail_subject_lost_password: Parola clair.ro|PM
mail_subject_lost_password: Your Redmine password
mail_body_lost_password: 'To change your Redmine password, click on the following link:'
mail_subject_register: Activare cont clair.ro|PM
mail_subject_register: Redmine account activation
mail_body_register: 'To activate your Redmine account, click on the following link:'
gui_validation_error: 1 eroare
@ -537,3 +537,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -537,3 +537,4 @@ default_activity_development: Разработка
enumeration_issue_priorities: Приоритеты задач
enumeration_doc_categories: Категории документов
enumeration_activities: Действия (учет времени)
setting_time_format: Time format

View File

@ -538,3 +538,4 @@ label_float: Float
button_copy: Copy
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -538,3 +538,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -540,3 +540,4 @@ mail_body_account_information_external: You can use your "%s" account to log int
mail_body_account_information: Your Redmine account information
setting_protocol: Protocol
label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
setting_time_format: Time format

View File

@ -75,4 +75,32 @@ class ApplicationHelperTest < HelperTestCase
text = "{{hello_world}}"
assert textilizable(text).match(/Hello world!/)
end
def test_date_format_default
today = Date.today
Setting.date_format = ''
assert_equal l_date(today), format_date(today)
end
def test_date_format
today = Date.today
Setting.date_format = '%d %m %Y'
assert_equal today.strftime('%d %m %Y'), format_date(today)
end
def test_time_format_default
now = Time.now
Setting.date_format = ''
Setting.time_format = ''
assert_equal l_datetime(now), format_time(now)
assert_equal l_time(now), format_time(now, false)
end
def test_time_format
now = Time.now
Setting.date_format = '%d %m %Y'
Setting.time_format = '%H %M'
assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
assert_equal now.strftime('%H %M'), format_time(now, false)
end
end