Skip to content

Commit

Permalink
Adjusted mt:OrderDate handler to directly use _hdlr_date() while zero…
Browse files Browse the repository at this point in the history
…ing any set 'utc' attribute and removed previously required included package.

Signed-off-by: Charlie Gorichanaz <[email protected]>
  • Loading branch information
CNG committed Oct 11, 2011
1 parent 679451a commit 12152f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 57 deletions.
3 changes: 1 addition & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ if it is the last item for a given day. Requires `order_by` variable set inside
## `mt:OrderDate` ##

A function tag that works like an `mt:Date` tag, for use within `mt:OrderDateHeader`
and `mt:OrderDateFooter` blocks. Does not take a `utc` attribute or support the
`relative` option of the `format` attribute.
and `mt:OrderDateFooter` blocks. Does not take a `utc` attribute.


# Changes #
Expand Down
62 changes: 7 additions & 55 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package Order::Plugin;

use MT::Util qw(format_ts); # Required by _hdlr_order_date() below

sub _natural_sort {
sort {
$a->[0] =~ m{ \A [+-]? \d+ }xms && $b->[0] =~ m{ \A [+-]? \d+ }xms
Expand Down Expand Up @@ -187,60 +185,14 @@ sub tag_order_item {
}

sub _hdlr_order_date {
## This was taken from the Melody project's source code at
## https://github.com/openmelody/melody/blob/master/lib/MT/Template/ContextHandlers.pm#L11358
## Code to handle relative dates and the UTC attribute were removed
## Any bugs found in that code likely will need to be fixed here as well
my ( $ctx, $args ) = @_;
my $ts = $args->{ts} || $ctx->{current_timestamp};
my $tag = $ctx->stash('tag');
return
$ctx->error(
MT->translate(
"You used an [_1] tag without a date context set up.",
"MT$tag"
)
) unless defined $ts;
my $blog = $ctx->stash('blog');
unless ( ref $blog ) {
my $blog_id = $blog || $args->{offset_blog_id};
if ($blog_id) {
$blog = MT->model('blog')->load($blog_id);
return $ctx->error(
MT->translate( 'Can\'t load blog #[_1].', $blog_id ) )
unless $blog;
}
my ($ctx, $args) = @_;
# Order dates are already UTC (or at least shouldn't be messed with after ordering).
if ($args->{utc}) {
my $tag = $ctx->stash('tag');
return $ctx->error(qq{The mt:$tag doesn't support a utc attribute: items were already ordered by these dates, so can't readjust them for UTC after the fact.});
}
my $lang
= $args->{language}
|| $ctx->var('local_lang_id')
|| ( $blog && $blog->language );
if ( my $format = lc( $args->{format_name} || '' ) ) {
my $tz = 'Z';
my $so = ( $blog && $blog->server_offset )
|| MT->config->TimeOffset;
my $partial_hour_offset = 60 * abs( $so - int($so) );
if ( $format eq 'rfc822' ) {
$tz = sprintf( "%s%02d%02d",
$so < 0 ? '-' : '+',
abs($so), $partial_hour_offset );
}
elsif ( $format eq 'iso8601' ) {
$tz = sprintf( "%s%02d:%02d",
$so < 0 ? '-' : '+',
abs($so), $partial_hour_offset );
}
if ( $format eq 'rfc822' ) {
## RFC-822 dates must be in English.
$args->{'format'} = '%a, %d %b %Y %H:%M:%S ' . $tz;
$lang = 'en';
}
elsif ( $format eq 'iso8601' ) {
$args->{format} = '%Y-%m-%dT%H:%M:%S' . $tz;
}
} ## end if ( my $format = lc( ...))
my $mail_flag = $args->{mail} || 0;
return format_ts( $args->{'format'}, $ts, $blog, $lang, $mail_flag );
return $ctx->_hdlr_date($args);
}


1;

0 comments on commit 12152f3

Please sign in to comment.