diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c03f073c..e9ea74e2 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 1c953f4c..4d4cf004 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 cc54eac9..c902d60a 100644 --- a/app/views/projects/activity.rhtml +++ b/app/views/projects/activity.rhtml @@ -4,7 +4,7 @@
<%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %>
+
<%= format_time(e.event_datetime, false) %> <%= link_to truncate(e.event_title, 100), e.event_url %>
<% unless e.event_description.blank? %><%= truncate(e.event_description, 500) %>
<% end %>
-<%= select_tag 'settings[date_format]', options_for_select( [[l(:label_language_based), '0'], ['ISO 8601 (YYYY-MM-DD)', '1']], Setting.date_format) %>
+<%= 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) %> + ++<%= 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) %>
<%= text_field_tag 'settings[attachment_max_size]', Setting.attachment_max_size, :size => 6 %> KB
diff --git a/config/settings.yml b/config/settings.yml index 333203f0..c59a5242 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -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: diff --git a/lang/bg.yml b/lang/bg.yml index 06ad0c39..09a94397 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -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 diff --git a/lang/cs.yml b/lang/cs.yml index 261b41d8..493bc77a 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -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 diff --git a/lang/de.yml b/lang/de.yml index c0389fb3..7463e93e 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -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 diff --git a/lang/en.yml b/lang/en.yml index 00a4886d..c51a76c8 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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 diff --git a/lang/es.yml b/lang/es.yml index ca4ede61..6807cacb 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -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 diff --git a/lang/fr.yml b/lang/fr.yml index 34596808..a44604a0 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -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 diff --git a/lang/he.yml b/lang/he.yml index 46015d6f..089cfdc7 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -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 diff --git a/lang/it.yml b/lang/it.yml index 2cf222c1..13c84893 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -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 diff --git a/lang/ja.yml b/lang/ja.yml index 03544f97..6fd8dfcc 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -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 diff --git a/lang/ko.yml b/lang/ko.yml index 020b70cd..9998f2f6 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -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 diff --git a/lang/nl.yml b/lang/nl.yml index 81f3f0ae..ab1913e1 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -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 diff --git a/lang/pl.yml b/lang/pl.yml index 6ada8c3a..0b433bac 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -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 diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 05bd4bcb..d4f51b61 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -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 diff --git a/lang/pt.yml b/lang/pt.yml index b6c16b45..bfd89bba 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -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 diff --git a/lang/ro.yml b/lang/ro.yml index 0f3f5d14..049efa7b 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -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 diff --git a/lang/ru.yml b/lang/ru.yml index 3acddd60..77ff6ec5 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -537,3 +537,4 @@ default_activity_development: Разработка enumeration_issue_priorities: Приоритеты задач enumeration_doc_categories: Категории документов enumeration_activities: Действия (учет времени) +setting_time_format: Time format diff --git a/lang/sr.yml b/lang/sr.yml index 7a06ca8a..1072af7e 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -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 diff --git a/lang/sv.yml b/lang/sv.yml index fce6a71d..d22b5c47 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -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 diff --git a/lang/zh.yml b/lang/zh.yml index 9e4b7e93..19e5b122 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -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 diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index b3ed9102..06446d15 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -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