This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Schema/ResultSet/Transaction.pm

46 lines
883 B
Perl
Raw Normal View History

2017-05-16 20:30:38 +00:00
package Pear::LocalLoop::Schema::ResultSet::Transaction;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
use DateTime;
2017-05-16 21:45:49 +00:00
sub search_between {
my ( $self, $from, $to ) = @_;
2017-05-16 20:30:38 +00:00
my $dtf = $self->result_source->schema->storage->datetime_parser;
return $self->search({
2017-08-14 15:10:14 +00:00
purchase_time => {
2017-05-16 20:30:38 +00:00
-between => [
2017-05-16 21:45:49 +00:00
$dtf->format_datetime($from),
$dtf->format_datetime($to),
2017-05-16 20:30:38 +00:00
],
},
});
}
2017-05-16 21:45:49 +00:00
sub today_rs {
my ( $self ) = @_;
my $today = DateTime->today();
return $self->search_between( $today, $today->clone->add( days => 1 ) );
}
sub week_rs {
my ( $self ) = @_;
my $today = DateTime->today();
return $self->search_between( $today->clone->subtract( days => 7 ), $today );
}
sub month_rs {
my ( $self ) = @_;
my $today = DateTime->today();
return $self->search_between( $today->clone->subtract( days => 30 ), $today );
2017-05-16 20:30:38 +00:00
}
1;