Skip to content

Commit

Permalink
refactoring. added format method to time-class. outputs time in a lan…
Browse files Browse the repository at this point in the history
…guage-specific style (for now: english & german)
  • Loading branch information
bakkdoor committed Sep 3, 2008
1 parent b215ce0 commit fde5d28
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/app/helpers/messages_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module MessagesHelper

def reply_message(old_message)
new_message = " \n\n------------------------\n#{old_message.author.login} wrote (#{old_message.created_at.german :long}):\n_#{old_message.body}_"
new_message = " \n\n------------------------\n#{old_message.author.login} wrote (#{old_message.created_at.format(:language => current_user.language, :format => :long)}):\n_#{old_message.body}_"
end

end
4 changes: 3 additions & 1 deletion src/app/views/account/index.rhtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="headline"><%= l :account %>: <%= current_user.login %> - <%= l :last_login %>: <%= @last_login.german(:long_clock) %></div>
<div class="headline">
<%= l :account %>: <%= current_user.login %> - <%= l :last_login %>: <%= @last_login.format(:lang => current_user.language, :format => :long) %>
</div>
<%= l :you_currently_have_a_user_status_of %>: <%= User.level_name(current_user.user_level).capitalize %><br>
<br>
<div class="headline"><%= l :news %></div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/account/settings.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</tr>
<tr>
<td class="title"><%= l :member_since %></td>
<td class="value"><%= current_user.created_at.german(:long_clock) %></td>
<td class="value"><%= current_user.created_at.format(:lang => current_user.language, :format => :long) %></td>
</tr>
<tr>
<td class="title"><%= l :language %></td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/messages/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<td><%= link_to (h message.title), message %></td>
<td><%= link_to (h message.author.login), message.author %></td>
<td><%= link_to (h message.receiver.login), message.receiver %></td>
<td><%=h message.created_at.german :long %></td>
<td><%=h message.created_at.format :lang => current_user.language, :format => :long %></td>
<td><%= link_to (l :reply), :action => :reply, :id => message %></td>
<td><%= link_to (l :destroy), message, :confirm => (l :are_you_sure?), :method => :delete %></td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/messages/sent.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<td><%= link_to (h message.title), message %></td>
<td><%= link_to (h message.author.login), message.author %></td>
<td><%= link_to (h message.receiver.login), message.receiver %></td>
<td><%=h message.created_at.german :long %></td>
<td><%=h message.created_at.format :lang => current_user.language, :format => :long %></td>
<td><%= link_to (l :destroy), message, :confirm => (l :are_you_sure?), :method => :delete %></td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/messages/show.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<p>
<b>Date:</b>
<%=h @message.created_at.german :long %>
<%=h @message.created_at.format :lang => current_user.language, :format => :long %>
</p>

<p>
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/project_memberships/_membership_info.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</tr>
<tr>
<td class="title"><%= l :created_at %></td>
<td class="value"><%= @membership.project.created_at.german %></td>
<td class="value"><%= @membership.project.created_at.format :lang => current_user.language %></td>
</tr>
<tr>
<td class="title"><%= l :updated_at %></td>
<td class="value"><%= @membership.project.updated_at.german %></td>
<td class="value"><%= @membership.project.updated_at.format :lang => current_user.language %></td>
</tr>
<tr>
<td class="title"><%= l :project_members %></td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/project_memberships/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<td><%=h project_membership.user.login %></td>
<td><%=h project_membership.project.name %></td>
<td><%=h project_membership.user_level %></td>
<td><%=h project_membership.created_at.german :long %></td>
<td><%=h project_membership.created_at.format :lang => current_user.language, :format => :long %></td>
<td><%= link_to 'Show', project_membership %></td>
<td><%= link_to 'Edit', edit_project_membership_path(project_membership) %></td>
<td><%= link_to 'Destroy', project_membership, :confirm => 'Are you sure?', :method => :delete %></td>
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/projects/_project_info.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</tr>
<tr>
<td class="title"><%= l :created_at %></td>
<td class="value"><%= @project.created_at.german %></td>
<td class="value"><%= @project.created_at.format :lang => current_user.language, :format => %></td>
</tr>
<tr>
<td class="title"><%= l :updated_at %></td>
<td class="value"><%= @project.updated_at.german %></td>
<td class="value"><%= @project.updated_at.format :lang => current_user.language, :format => %></td>
</tr>
<tr>
<td class="title"><%= l :project_members %></td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/projects/_project_list.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= link_to project.name, :controller => :projects, :action => :show, :id => project.id %>
</div>
<div style="float:right;font-size:90%;padding-top:0.5em">
<%= project.updated_at.german %>
<%= project.updated_at.format :lang => current_user.language %>
</div>
</div>
<div id="body" style="display:block">
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/users/_auto_complete_results.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% for user in @users do -%>
<li class="user">
<div style="text-align:left"><%= link_to (h user.login), :action => "show", :id => user %></div>
<div style="text-align:left">Dabei seit: <%= h user.created_at.german %></div>
<div style="text-align:left">Dabei seit: <%= h user.created_at.format :lang => current_user.language %></div>
</li>
<% end -%>
</ul>
2 changes: 1 addition & 1 deletion src/app/views/users/show.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</tr>
<tr>
<td class="title"><%= l :member_since %></td>
<td class="value"><%= @profile_user.created_at.german(:long_clock) %></td>
<td class="value"><%= @profile_user.created_at.format :lang => current_user.language, :format => :long %></td>
</tr>
</table>
</div>
Expand Down
53 changes: 29 additions & 24 deletions src/lib/time_enhancement.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# small enhancements to time class
module TimeEnhancement

def german(long_date = false)

db_date = self.to_s(:db)
date_en = db_date.split(" ")[0]
time_en = db_date.split(" ")[1]

date_split = date_en.split("-")
time_split = time_en.split(":")

hour = time_split[0]
minute = time_split[1]

day = date_split[2]
month = date_split[1]
year = date_split[0]

if long_date == :long
"#{day}.#{month}.#{year} - #{hour}:#{minute}"
elsif long_date == :long_clock
"#{day}.#{month}.#{year} - #{hour}:#{minute} Uhr"
else
"#{day}.#{month}.#{year}"
end
end
def german(format = :short)
case format
when :long
self.strftime("%d.%m.%Y - %H:%M")
else
self.strftime("%d.%m.%Y")
end
end

def english(format = :short)
case format
when :long
self.strftime("%m.%d.%Y - %H:%M")
else
self.strftime("%m.%d.%Y")
end
end

def format(options = {})
lang = options[:lang] || Language.default
format = options[:format]

output = case lang
when "de"
german(format)
when "en"
english(format)
end
end

end

0 comments on commit fde5d28

Please sign in to comment.