From 6d5282c5dd73fa0173184fe13228f5885f9d8163 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Sun, 8 Jan 2017 11:33:59 -0600 Subject: [PATCH] Format copyright year as "X - Y" when the year in the config is not the current year --- Changes | 3 +++ lib/Dist/Zilla.pm | 8 +++++++- t/plugins/license.t | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index bd14add36..650d2c499 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ Revision history for {{$dist->name}} {{$NEXT}} + - if the copyright_year in the dist.ini is not this year, the + copyright statement and license are formatted as "$year - + $current_year" (Dave Rolsky, github #578) 6.008 2016-10-05 21:35:23-04:00 America/New_York - fix the skip message from ExtraTests (thanks, Roy Ivy Ⅲ!) diff --git a/lib/Dist/Zilla.pm b/lib/Dist/Zilla.pm index 873ceb75d..034fd1019 100644 --- a/lib/Dist/Zilla.pm +++ b/lib/Dist/Zilla.pm @@ -383,9 +383,15 @@ sub _build_license { ); } + my $this_year = (localtime)[5] + 1900; + my $years + = $copyright_year == $this_year + ? $copyright_year + : "$copyright_year - $this_year"; + my $license = $license_class->new({ holder => $self->_copyright_holder, - year => $self->_copyright_year, + year => $years, }); $self->_clear_license_class; diff --git a/t/plugins/license.t b/t/plugins/license.t index 89081caf5..f986f68d3 100644 --- a/t/plugins/license.t +++ b/t/plugins/license.t @@ -11,7 +11,7 @@ subtest "ASCII-only author" => sub { { dist_root => 'corpus/dist/DZT' }, { add_files => { - 'source/dist.ini' => simple_ini('License'), + 'source/dist.ini' => simple_ini({ copyright_year => 2012 }, 'License'), }, }, ); @@ -22,7 +22,7 @@ subtest "ASCII-only author" => sub { like( $contents, - qr{This software is copyright .c. [0-9]+ by E\. Xavier Ample}i, + qr{This software is copyright .c. 2012 - \d\d\d\d by E\. Xavier Ample}i, "copyright appears in LICENSE file", );