diff options
-rw-r--r-- | app/helpers/application_helper.rb | 10 | ||||
-rw-r--r-- | app/models/setting.rb | 17 | ||||
-rw-r--r-- | app/views/projects/activity.rhtml | 2 | ||||
-rw-r--r-- | app/views/settings/edit.rhtml | 5 | ||||
-rw-r--r-- | config/settings.yml | 7 | ||||
-rw-r--r-- | lang/bg.yml | 1 | ||||
-rw-r--r-- | lang/cs.yml | 1 | ||||
-rw-r--r-- | lang/de.yml | 1 | ||||
-rw-r--r-- | lang/en.yml | 3 | ||||
-rw-r--r-- | lang/es.yml | 1 | ||||
-rw-r--r-- | lang/fr.yml | 3 | ||||
-rw-r--r-- | lang/he.yml | 1 | ||||
-rw-r--r-- | lang/it.yml | 1 | ||||
-rw-r--r-- | lang/ja.yml | 1 | ||||
-rw-r--r-- | lang/ko.yml | 1 | ||||
-rw-r--r-- | lang/nl.yml | 1 | ||||
-rw-r--r-- | lang/pl.yml | 1 | ||||
-rw-r--r-- | lang/pt-br.yml | 1 | ||||
-rw-r--r-- | lang/pt.yml | 1 | ||||
-rw-r--r-- | lang/ro.yml | 13 | ||||
-rw-r--r-- | lang/ru.yml | 1 | ||||
-rw-r--r-- | lang/sr.yml | 1 | ||||
-rw-r--r-- | lang/sv.yml | 1 | ||||
-rw-r--r-- | lang/zh.yml | 1 | ||||
-rw-r--r-- | 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 @@ <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 %> diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml index b08b707bf..62aa7974c 100644 --- a/app/views/settings/edit.rhtml +++ b/app/views/settings/edit.rhtml @@ -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> diff --git a/config/settings.yml b/config/settings.yml index 333203f03..c59a5242e 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 06ad0c39d..09a943973 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 261b41d8b..493bc77a5 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 c0389fb34..7463e93ec 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 00a4886da..c51a76c80 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 ca4ede610..6807cacb9 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 345968088..a44604a0d 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 46015d6f9..089cfdc7d 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 2cf222c1b..13c848935 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 03544f971..6fd8dfcc6 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 020b70cd8..9998f2f64 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 81f3f0aeb..ab1913e19 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 6ada8c3af..0b433bacb 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 05bd4bcb8..d4f51b61d 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 b6c16b452..bfd89bbae 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 0f3f5d144..049efa7b1 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 3acddd607..77ff6ec5e 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 7a06ca8a2..1072af7eb 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 fce6a71d6..d22b5c478 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 9e4b7e931..19e5b122b 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 b3ed9102e..06446d15e 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 |