From ebc29c5f4a7cef14ff3207a0aa066040f091177b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 5 Dec 2025 14:26:48 +0000 Subject: [PATCH] Bug 41387: Add 2 digit day option as well While adding 2 digit months, let's add 2 digit days as well. These are necessary to ensure correct sorting, that is the reason for this request To test: 0 - Apply patch 1 - Setup a new numbering pattern Serials->Manage numbering patterns + New numbering pattern 2 - In the numbering formula enter: {X} {Y} {Z} {Year} {Month} {Month2} {Day} {Day2} {MonthName} {DayName} 3 - Populate X/Y/Z in the table as you wish, these should be unaffected by patch 4 - Set a Frequency / First issue plublication date / Subscription length 5 - Click 'Test pattern' 6 - Confirm the dates in the Number match the publication date values 7 - Try with different frequencies to confirm they match 8 - Save the pattern 9 - Create a new subscription and use the new pattern 10 - Confirm it works as expected Signed-off-by: David Nind --- C4/Serials.pm | 2 ++ t/db_dependent/Serials.t | 28 ++++++---------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 02adb23819..e6a669eefe 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -921,6 +921,7 @@ sub GetNextSeq { $calculated =~ s/\{MonthName\}/$dt->month_name/eg; $calculated =~ s/\{Year\}/$dt->year/eg; $calculated =~ s/\{Day\}/$dt->day/eg; + $calculated =~ s/\{Day2\}/sprintf("%02d", $dt->day())/eg; $calculated =~ s/\{DayName\}/$dt->day_name/eg; } @@ -973,6 +974,7 @@ sub GetSeq { $calculated =~ s/\{MonthName\}/$dt->month_name/eg; $calculated =~ s/\{Year\}/$dt->year/eg; $calculated =~ s/\{Day\}/$dt->day/eg; + $calculated =~ s/\{Day2\}/sprintf("%02d", $dt->day())/eg; $calculated =~ s/\{DayName\}/$dt->day_name/eg; return $calculated; diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 2fcaf8ef24..e0e553878e 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -704,7 +704,7 @@ subtest "NewSubscription|ModSubscription" => sub { }; subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub { - plan tests => 6; + plan tests => 4; $subscription = { lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1, innerloop1 => 0, innerloop2 => 0, innerloop3 => 0, @@ -714,45 +714,29 @@ subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub { firstacquidate => '1970-11-01', }; $pattern = { - numberingmethod => '{Year} {Day} {DayName} {Month} {MonthName}', + numberingmethod => '{Year} {Day} {Day2} {DayName} {Month} {Month2} {MonthName}', }; my $numbering = GetSeq( $subscription, $pattern ); - is( $numbering, '1970 1 Sunday 11 November', 'GetSeq correctly calculates numbering from first aqui date' ); + is( $numbering, '1970 1 01 Sunday 11 11 November', 'GetSeq correctly calculates numbering from first aqui date' ); $subscription->{firstacquidate} = '2024-02-29'; $numbering = GetSeq( $subscription, $pattern ); is( - $numbering, '2024 29 Thursday 2 February', + $numbering, '2024 29 29 Thursday 2 02 February', 'GetSeq correctly calculates numbering from first aqui date, leap year' ); my $planneddate = '1970-11-01'; ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate ); - is( $numbering, '1970 1 Sunday 11 November', 'GetNextSeq correctly calculates numbering from planned date' ); + is( $numbering, '1970 1 01 Sunday 11 11 November', 'GetNextSeq correctly calculates numbering from planned date' ); $planneddate = '2024-02-29'; ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate ); is( - $numbering, '2024 29 Thursday 2 February', + $numbering, '2024 29 29 Thursday 2 02 February', 'GetNextSeq correctly calculates numbering from planned date, leap year' ); - $pattern = { - numberingmethod => '{Year} {Day} {DayName} {Month2} {MonthName}', - }; - $subscription->{firstacquidate} = '2024-02-29'; - $planneddate = '2024-02-29'; - $numbering = GetSeq( $subscription, $pattern ); - is( - $numbering, '2024 29 Thursday 02 February', - 'GetSeq correctly calculates 2 digit month numbering from first aqui date, leap year' - ); - ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate ); - is( - $numbering, '2024 29 Thursday 02 February', - 'GetNextSeq correctly calculates 2 digit month numbering from planned date, leap year' - ); - }; subtest "DelSubscription" => sub { -- 2.39.5