Permalink
Browse files

Merge pull request #93 from keedi/master

Support timezone for logged in user
  • Loading branch information...
2 parents 2a0ba94 + 03826d2 commit 5e4d7ee6433818b2eed4902d7c1e245478ec7676 @marcusramberg marcusramberg committed Sep 2, 2011
View
15 lib/MojoMojo.pm
@@ -20,6 +20,7 @@ use Catalyst qw/
use Storable;
use Digest::MD5;
use Data::Dumper;
+use DateTime;
use MRO::Compat;
use DBIx::Class::ResultClass::HashRefInflator;
use Encode ();
@@ -292,6 +293,20 @@ sub fixw {
return $w;
}
+=head2 tz
+
+Convert timezone
+
+=cut
+
+sub tz {
+ my ( $c, $dt ) = @_;
+ if ( $c->user && $c->user->timezone ) {
+ eval { $dt->set_time_zone( $c->user->timezone ) };
+ }
+ return $dt;
+}
+
=head2 prepare_action
Provide "No DB" message when one needs to spawn the db (script/mojomojo_spawn.pl).
View
2 root/base/comment.tt
@@ -10,7 +10,7 @@
<dt>[% loc('poster') %]</dt>
<dd><a href="[%comment.poster.link%]">[%comment.poster.name%]</a></dd>
<dt>[% loc('posted') %]</dt>
- <dd>[% comment.posted.ymd %] [% comment.posted.hms %]</dd>
+ <dd>[% c.tz(comment.posted).ymd %] [% c.tz(comment.posted).hms %]</dd>
<dt>
[% loc('comment') %]:
[% IF user.can_edit(page.path) %]
View
4 root/base/page/atom.tt
@@ -4,7 +4,7 @@
<link rel="alternate" type="text/html" href="[% c.uri_for('view') %]" />
<modified>[% page.content.created.datetime %]-00:00</modified>
<tagline> [%loc('Recent changes in x',page.path)%]</tagline>
-<id>tag:[%c.base_uri.host%],[%page.content.created.ymd('-')%]:[%page.path%]</id>
+<id>tag:[%c.base_uri.host%],[%c.tz(page.content.created).ymd('-')%]:[%page.path%]</id>
<generator url="[%base%]" version="0.1">[% title || "MojoMojo"%]</generator>
[%FOREACH page IN pages %]
[% IF c.check_permissions(page.path,c.user).view %]
@@ -14,7 +14,7 @@
<modified>[% page.content.created.datetime %]-00:00</modified>
<issued>[%IF page.revisions %][% page.revisions.last.updated.datetime %][%
ELSE %][% page.content.created.datetime %][% END %]-00:00</issued>
-<id>tag:[% c.base_uri.host %],[% page.content.created.ymd('-') %]:[% page.path %]</id>
+<id>tag:[% c.base_uri.host %],[% c.tz(page.content.created).ymd('-') %]:[% page.path %]</id>
<created>[% IF page.revisions %][% page.revisions.last.updated.datetime %][%
ELSE %][% page.content.created.datetime %][% END %]-00:00</created>
<summary type="text/plain">[% page.content.body %]</summary>
View
2 root/base/page/print.tt
@@ -10,7 +10,7 @@
[% content.formatted(c) %]
</div>
<div class="byline">
- [% loc('Revised on x at x by x', [content.created.ymd, content.created.hms, content.creator.name]) %]
+ [% loc('Revised on x at x by x', [c.tz(content.created).ymd, c.tz(content.created).hms, content.creator.name]) %]
</div>
</div>
</div>
View
8 root/base/page/recent.tt
@@ -7,7 +7,7 @@
IF activetag;
SET title = loc('Recent pages in x tagged with x', [page.path, activetag]);
END;
- SET now = objects.first.content.created.ymd;
+ SET now = c.tz(objects.first.content.created).ymd;
%]
[% WRAPPER page/wrapper.tt title = title %]
@@ -31,12 +31,12 @@
[% first = 1 %]
[% FOREACH page IN pages %]
[% IF c.check_permissions(page.path,c.user).view %]
- [% IF now != page.content.created.ymd; %]
+ [% IF now != c.tz(page.content.created).ymd; %]
[% IF first; first = 0; ELSE %]
</tbody></table>
[% END %]
- [% SET now = page.content.created.ymd %]
+ [% SET now = c.tz(page.content.created).ymd %]
<h3>[% now %]</h3>
<table class="recent">
<thead>
@@ -58,7 +58,7 @@
<a href="[% c.req.base; page.content.creator.link _ '.profile'; %]">[% page.content.creator.name %]</a>
</td>
<td>
- [% page.content.created.hms(":") %]
+ [% c.tz(page.content.created).hms(":") %]
</td>
<td><a rel="nofollow" href="[% c.uri_for('jsrpc/diff', page.id , 0, 0, 1) %]" class="diff_link">[% loc('View Diff') %]</a></td>
</tr>
View
2 root/base/page/search_inline.tt
@@ -33,7 +33,7 @@
<div class="snippet">[% result.snippet %]</div>
<div class="byline">
[% loc('by') %] [% c.wikiword(result.page.content.creator.link, base) %]
- [% loc('on') %] <small>[% result.page.content.created.ymd("-") %]</small>
+ [% loc('on') %] <small>[% c.tz(result.page.content.created).ymd("-") %]</small>
</div>
</li>
[% END +%]
View
6 root/base/page/view.tt
@@ -12,7 +12,7 @@
[%- IF c.req.params.rev %]
<div id="revision_info">
- [% loc('Revision') %] [% c.req.params.rev %] - [% content.created.ymd %] [% loc('at') %] [% content.created.hms %]
+ [% loc('Revision') %] [% c.req.params.rev %] - [% c.tz(content.created).ymd %] [% loc('at') %] [% c.tz(content.created).hms %]
[% IF c.req.params.rev > page.content_version %]
<em>[% loc('Rolled Back (Current: x)', page.content_version) %]</em>
[% END %]
@@ -37,8 +37,8 @@
</div>
<div class="byline">
- <acronym title="[% loc('Revised on x at x by x', [content.created.ymd, content.created.hms, content.creator.name]) %]">[% loc('Revision') %]</acronym>
- [% loc('by') %] [% c.wikiword(content.creator.link, base, content.creator.name, 'profile') %], [% content.created.ymd %]
+ <acronym title="[% loc('Revised on x at x by x', [c.tz(content.created).ymd, c.tz(content.created).hms, content.creator.name]) %]">[% loc('Revision') %]</acronym>
+ [% loc('by') %] [% c.wikiword(content.creator.link, base, content.creator.name, 'profile') %], [% c.tz(content.created).ymd %]
</div>
</div>
View
8 root/base/tag/recent.tt
@@ -1,5 +1,5 @@
[% PROCESS header.tt %]
-[% SET now=pages.first.updated.ymd; %]
+[% SET now=c.tz(pages.first.updated).ymd; %]
<div id="header"><h1 id="pageName"> [% loc('Recent Pages') %] </h1></div>
[% PROCESS breadcrumbs.tt %]
[% PROCESS navbar.tt %]
@@ -16,15 +16,15 @@
<b>[% now %]</b>
<ul>
[% FOREACH page IN pages %]
-[% IF now != page.content.created.ymd; %]
- [% SET now = page.content.created.ymd; %]
+[% IF now != c.tz(page.content.created).ymd; %]
+ [% SET now = c.tz(page.content.created).ymd; %]
</ul><b>[% now %]</b><ul>
[% END %]
<li>
<a href="[% c.uri_for( page.path )%]">[% c.expand_wikilink(page.name) %]</a>
<div class="byline" style="margin-bottom: 0px">
[% loc('by') %] <a class="existingWikiWord" href="[% c.uri_for( page.content.creator.link) %]">[% page.content.creator.name %]</a>
- [% loc('at') %] [% page.content.created.hms(':') %]
+ [% loc('at') %] [% c.tz(page.content.created).hms(':') %]
</div>
</li>
[% END %]
View
7 root/base/user/profile.tt
@@ -32,6 +32,11 @@
<dd>[% person.gender %]</dd>
[%+ END %]
+ [% IF person.timezone +%]
+ <dt>[% loc('Timezone') %]:</dt>
+ <dd>[% person.timezone %]</dd>
+ [%+ END %]
+
[% IF person.industry +%]
<dt>[% loc('Industry') %]:</dt>
<dd>[% person.industry %]</dd>
@@ -52,7 +57,7 @@
<dd>[% person.movies_formatted %]</dd>
[%+ END +%]
<dt>[% loc('Date registered') %]:</dt>
- <dd>[% person.registered.ymd %]</dd>
+ <dd>[% c.tz(person.registered).ymd %]</dd>
<dt>[% loc('Edits') %]:<dt>
<dd>
View
3 root/forms/user/editprofile.yml
@@ -21,6 +21,9 @@ elements:
- [ 'f', 'Female' ]
- [ '?', 'Rather not say' ]
- type: Text
+ name: timezone
+ label_loc: Timezone
+ - type: Text
name: industry
label_loc: Industry
- type: Textarea

0 comments on commit 5e4d7ee

Please sign in to comment.