[libdatetime-timezone-perl] 04/09: Don't call sprintf when there's no format specifier

gregor herrmann gregoa at debian.org
Wed Apr 15 19:03:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

gregoa pushed a commit to annotated tag v1.82
in repository libdatetime-timezone-perl.

commit ab53aabe106391b57f9559c4bdfa2a4329a5f383
Author: Dave Rolsky <autarch at urth.org>
Date:   Sat Nov 22 15:58:03 2014 -0600

    Don't call sprintf when there's no format specifier
---
 lib/DateTime/TimeZone/OlsonDB/Observance.pm | 12 +++++++++++-
 lib/DateTime/TimeZone/OlsonDB/Zone.pm       |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/DateTime/TimeZone/OlsonDB/Observance.pm b/lib/DateTime/TimeZone/OlsonDB/Observance.pm
index 5c75acd..daf198a 100644
--- a/lib/DateTime/TimeZone/OlsonDB/Observance.pm
+++ b/lib/DateTime/TimeZone/OlsonDB/Observance.pm
@@ -88,6 +88,16 @@ sub format { $_[0]->{format} }
 sub utc_start_datetime   { $_[0]->{utc_start_datetime} }
 sub local_start_datetime { $_[0]->{local_start_datetime} }
 
+sub formatted_short_name {
+    my $self   = shift;
+    my $letter = shift;
+
+    my $format = $self->format;
+    return $format unless $format =~ /%/;
+
+    return sprintf( $format, $letter );
+}
+
 sub expand_from_rules {
     my $self = shift;
     my $zone = shift;
@@ -150,7 +160,7 @@ sub expand_from_rules {
                 local_start_datetime => $dt + DateTime::Duration->new(
                     seconds => $self->total_offset + $rule->offset_from_std
                 ),
-                short_name => sprintf( $self->{format}, $rule->letter ),
+                short_name => $self->formatted_short_name( $rule->letter ),
                 observance => $self,
                 rule       => $rule,
             );
diff --git a/lib/DateTime/TimeZone/OlsonDB/Zone.pm b/lib/DateTime/TimeZone/OlsonDB/Zone.pm
index d8ec62e..ae7a063 100644
--- a/lib/DateTime/TimeZone/OlsonDB/Zone.pm
+++ b/lib/DateTime/TimeZone/OlsonDB/Zone.pm
@@ -77,7 +77,7 @@ sub expand_observances {
             type                 => 'observance',
             utc_start_datetime   => $obs->utc_start_datetime,
             local_start_datetime => $obs->local_start_datetime,
-            short_name           => sprintf( $obs->format, $letter ),
+            short_name           => $obs->formatted_short_name($letter),
             observance           => $obs,
             $rule ? ( rule => $rule ) : (),
         );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdatetime-timezone-perl.git



More information about the Pkg-perl-cvs-commits mailing list