Skip to content

Instantly share code, notes, and snippets.

@steveh
Forked from davidlee/gist:214687
Created October 21, 2009 00:19
Show Gist options
  • Save steveh/214736 to your computer and use it in GitHub Desktop.
Save steveh/214736 to your computer and use it in GitHub Desktop.
module ApplicationHelper
def local_time(time)
capture_haml do
haml_tag :span, time.utc.to_s, :class => 'time'
end
end
def local_date(time)
capture_haml do
haml_tag :span, time.to_time.utc.to_s, :class => 'date'
end
end
end
// global.js
$('span.time').each(function(){
utc_time = new Date($(this).html());
$(this).replaceWith(utc_time.toLocaleTimeString());
});
$('span.date').each(function(){
utc_time = new Date($(this).html());
$(this).replaceWith(utc_time.toLocaleDateString());
});
# example usage (haml)
%td.created
= local_date(ticket.created_at)
= local_time(ticket.created_at)
# example output (generated html)
<td class='created'>
<span class='date'>Tue Oct 20 22:17:14 UTC 2009</span>
<span class='time'>Tue Oct 20 22:17:14 UTC 2009</span>
</td>
# example output (rendered)
<td class="created">
10/21/2009
09:17:14
</td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment