use strict; use MT::Template::Context; use Time::Local; MT::Template::Context->add_tag('EpochSeconds' => sub { my ($ctx, $args) = @_; my $e = $ctx->stash('entry') or return $ctx->_no_entry_error('MTEpochSeconds'); my $b = $ctx->stash('blog'); my $timestamp = $e->created_on; my ($y, $m, $d, $h, $min, $s) = unpack('A4A2A2A2A2A2', $timestamp); $m--; # timelocal expects a zero-based month # We correct for timezone manually, rather than using timelocal, # so that we can use the user's timezone setting, not the # server's. my $secs = timegm($s, $min, $h, $d, $m, $y); my $offset = $b->server_offset; $offset *= -1; # because we're moving _from_ local _to_ GMT $offset *= 60*60; # in seconds $secs += $offset; return $secs; }); MT::Template::Context->add_tag('CommentEpochSeconds' => sub { my ($ctx, $args) = @_; my $e = $ctx->stash('comment') or return $ctx->_no_entry_error('MTEpochSeconds'); my $b = $ctx->stash('blog'); my $timestamp = $e->created_on; my ($y, $m, $d, $h, $min, $s) = unpack('A4A2A2A2A2A2', $timestamp); $m--; # timelocal expects a zero-based month # We correct for timezone manually, rather than using timelocal, # so that we can use the user's timezone setting, not the # server's. my $secs = timegm($s, $min, $h, $d, $m, $y); my $offset = $b->server_offset; $offset *= -1; # because we're moving _from_ local _to_ GMT $offset *= 60*60; # in seconds $secs += $offset; return $secs; });