package MT::Plugin::JalaliDate; # Copyright (C) 2002,2003 Hamid Hashemi # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You can receive a copy of GNU Lesser General Public License at the # World Wide Web address . # # For licensing issues, contact Hamid Hashemi . # ########################################################################### ########################################################################### use MT::Template::Context; use MT::Util qw( offset_time_list ); MT::Template::Context->add_tag('JalaliDate' => sub{&_jalali_date;}); use JalaliDate; sub _jalali_date { my ($ctx, $args) = @_; my $blog_id = $ctx->stash('blog_id'); my $j_date; if ( $ctx->stash('entry') ) { my $entry = $ctx->stash('entry'); $j_date = g2jstrftime( defined($args->{'format'})?$args->{'format'}:'%A، %d %B %Y' , $entry->created_on ); } if ( $ctx->stash('comment') ) { my $comment = $ctx->stash('comment'); $j_date = g2jstrftime( defined($args->{'format'})?$args->{'format'}:'%A، %d %B %Y، %h:%m %t' , $comment->created_on ); } if ( not defined($j_date) ) { my ($sec,$min,$hour,$day,$month,$year) = (offset_time_list(time, $blog_id))[0,1,2,3,4,5]; my $curstamp = sprintf("%04d%02d%02d%02d%02d%02d", $year + 1900, $month + 1, $day, $hour, $min, $sec); $j_date = g2jstrftime( defined($args->{'format'})?$args->{'format'}:'%b %Y' , $curstamp ); } if ( defined($args->{'numbers'}) ) { $j_date = farsi_number($j_date) if ( lc($args->{'numbers'}) eq 'farsi' ); } return $j_date; }