From 3f743f0b5ff5460e6838cebea62c2116702e4130 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 21 Aug 2017 15:16:29 +0100 Subject: [PATCH] Fixed all_day calculating from the wrong time --- .../LocalLoop/Schema/ResultSet/Transaction.pm | 9 +++++++++ t/schema/leaderboard.t | 16 ++++++++-------- t/schema/resultset_leaderboard.t | 16 ++++++++-------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm b/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm index 05d264d..822abf2 100644 --- a/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm +++ b/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm @@ -21,6 +21,15 @@ sub search_between { }); } +sub search_before { + my ( $self, $date ) = @_; + + my $dtf = $self->result_source->schema->storage->datetime_parser; + return $self->search({ + purchase_time => { '<' => $dtf->format_datetime( $date ) }, + }); +} + sub today_rs { my ( $self ) = @_; diff --git a/t/schema/leaderboard.t b/t/schema/leaderboard.t index 9f0e72f..5d09595 100644 --- a/t/schema/leaderboard.t +++ b/t/schema/leaderboard.t @@ -215,10 +215,10 @@ test_leaderboard( 'all_time_total', $now, [ - { user_id => 4, value => 980 }, - { user_id => 3, value => 940 }, - { user_id => 2, value => 900 }, - { user_id => 1, value => 860 }, + { user_id => 4, value => 885 }, + { user_id => 3, value => 855 }, + { user_id => 2, value => 825 }, + { user_id => 1, value => 795 }, ] ); @@ -227,10 +227,10 @@ test_leaderboard( 'all_time_count', $now, [ - { user_id => 1, value => 40 }, - { user_id => 2, value => 40 }, - { user_id => 3, value => 40 }, - { user_id => 4, value => 40 }, + { user_id => 1, value => 30 }, + { user_id => 2, value => 30 }, + { user_id => 3, value => 30 }, + { user_id => 4, value => 30 }, ] ); diff --git a/t/schema/resultset_leaderboard.t b/t/schema/resultset_leaderboard.t index 7245283..c1ab6b1 100644 --- a/t/schema/resultset_leaderboard.t +++ b/t/schema/resultset_leaderboard.t @@ -217,10 +217,10 @@ test_leaderboard( 'all_time_total', $now, [ - { user_id => 4, value => 980, position => 1 }, - { user_id => 3, value => 940, position => 2 }, - { user_id => 2, value => 900, position => 3 }, - { user_id => 1, value => 860, position => 4 }, + { user_id => 4, value => 885, position => 1 }, + { user_id => 3, value => 855, position => 2 }, + { user_id => 2, value => 825, position => 3 }, + { user_id => 1, value => 795, position => 4 }, ] ); @@ -229,10 +229,10 @@ test_leaderboard( 'all_time_count', $now, [ - { user_id => 1, value => 40, position => 1 }, - { user_id => 2, value => 40, position => 2 }, - { user_id => 3, value => 40, position => 3 }, - { user_id => 4, value => 40, position => 4 }, + { user_id => 1, value => 30, position => 1 }, + { user_id => 2, value => 30, position => 2 }, + { user_id => 3, value => 30, position => 3 }, + { user_id => 4, value => 30, position => 4 }, ] );