Bugzilla – Attachment 95212 Details for
Bug 23974
hours_between and days_between lack tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23974: Add tests for days_between
Bug-23974-Add-tests-for-daysbetween.patch (text/plain), 7.33 KB, created by
Martin Renvoize (ashimema)
on 2019-11-08 13:49:34 UTC
(
hide
)
Description:
Bug 23974: Add tests for days_between
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-11-08 13:49:34 UTC
Size:
7.33 KB
patch
obsolete
>From 2b7ba0e673c49169f39a9631afb7156c0ad7f885 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 5 Nov 2019 17:13:53 +0100 >Subject: [PATCH] Bug 23974: Add tests for days_between > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Calendar.t | 50 +++++++++++++++++++++++++++++++++------ > 1 file changed, 43 insertions(+), 7 deletions(-) > >diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t >index e24e9bc6bc..e3e82b5e1f 100644 >--- a/t/db_dependent/Calendar.t >+++ b/t/db_dependent/Calendar.t >@@ -92,7 +92,7 @@ subtest 'crossing_DST' => sub { > ); > }; > >-subtest 'hours_between' => sub { >+subtest 'hours_between | days_between' => sub { > > plan tests => 2; > >@@ -121,44 +121,60 @@ subtest 'hours_between' => sub { > > subtest 'Same hours' => sub { > >- plan tests => 4; >+ plan tests => 8; > > # Between 5th and 6th > my $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; > is( $diff_hours, 1 * 24, '' ); >+ my $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days; >+ is( $diff_days, 1, '' ); > > # Between 5th and 7th > $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; > is( $diff_hours, 2 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_7 )->delta_days; >+ is( $diff_days, 2, '' ); > > # Between 5th and 12th > $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; > is( $diff_hours, 7 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days; >+ is( $diff_days, 7, '' ); > > # Between 5th and 15th > $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; > is( $diff_hours, 10 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days; >+ is( $diff_days, 10, '' ); > }; > > subtest 'Different hours' => sub { > >- plan tests => 4; >+ plan tests => 8; > > # Between 5th and 6th > my $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 1 * 24 - 3, '' ); >+ my $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 1, '' ); > > # Between 5th and 7th > $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 2 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 2, '' ); > > # Between 5th and 12th > $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 7 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 7, '' ); > > # Between 5th and 15th > $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 10 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 10, '' ); > }; > }; > >@@ -177,56 +193,76 @@ subtest 'hours_between' => sub { > my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); > > subtest 'Same hours' => sub { >- plan tests => 5; >+ plan tests => 10; > >- my $diff_hours; >+ my ( $diff_hours, $diff_days ); > > # Between 5th and 6th > $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours; > is( $diff_hours, 0 * 24, '' ); # FIXME Is this really should be 0? >+ $diff_days = $calendar->days_between( $now, $nov_6)->delta_days; >+ is( $diff_days, 0, '' ); # FIXME Is this really should be 0? > > # Between 5th and 7th > $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours; > is( $diff_hours, 2 * 24 - 1 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_7)->delta_days; >+ is( $diff_days, 2 - 1, '' ); > > # Between 5th and 12th > $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours; > is( $diff_hours, 7 * 24 - 1 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_12)->delta_days; >+ is( $diff_days, 7 - 1, '' ); > > # Between 5th and 13th > $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours; > is( $diff_hours, 8 * 24 - 2 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_13)->delta_days; >+ is( $diff_days, 8 - 2, '' ); > > # Between 5th and 15th > $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours; > is( $diff_hours, 10 * 24 - 2 * 24, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_15)->delta_days; >+ is( $diff_days, 10 - 2, '' ); > }; > > subtest 'Different hours' => sub { >- plan tests => 6; >+ plan tests => 11; > >- my $diff_hours; >+ my ( $diff_hours, $diff_days ); > > # Between 5th and 6th > my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) ); > is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs > is( $duration->is_negative, 1, ); # FIXME Do really test for that case in our calls to hours_between? >+ $duration = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) ); >+ is( $duration->hours, abs(0), '' ); # FIXME Is this correct? > > # Between 5th and 7th > $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 2 * 24 - 1 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 2 - 1, '' ); > > # Between 5th and 12th > $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 7 * 24 - 1 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 7 - 1, '' ); > > # Between 5th and 13th > $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 8 * 24 - 2 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 8 - 1, '' ); > > # Between 5th and 15th > $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours; > is( $diff_hours, 10 * 24 - 2 * 24 - 3, '' ); >+ $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days; >+ is( $diff_days, 10 - 2, '' ); > }; > > }; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23974
:
95062
|
95063
|
95064
|
95065
|
95210
|
95211
|
95212
|
95213
|
95214
|
95889
|
95890
|
95891
|
95893
|
95894
|
95895
|
95896
|
96778
|
96779
|
96780
|
96781
|
96782
|
96783
|
96784
|
96785
|
96786
|
97129
|
97130
|
97131
|
97132
|
97133
|
97134
|
97135
|
97136
|
97137