1 package FS::part_event::Condition::signupdate;
4 use base qw( FS::part_event::Condition );
5 use FS::Record qw(str2time_sql str2time_sql_closing);
6 use Date::Parse 'str2time';
8 sub description { 'Customer signed up during date range' }
12 # actually stored as strings
13 'start' => { label => 'First day',
15 format => '%Y-%m-%d', },
16 'end' => { label => 'Last day',
18 format => '%Y-%m-%d', },
24 my($self, $object, %opt) = @_;
26 my $cust_main = $self->cust_main($object);
27 my $start = $self->option('start');
28 my $end = $self->option('end');
30 (!$start or $cust_main->signupdate >= str2time($start)) and
31 (!$end or $cust_main->signupdate < str2time($end) + 86400);
35 my( $class, $table, %opt ) = @_;
36 return 'true' if $opt{'driver_name'} ne 'Pg';
38 my $start = $class->condition_sql_option('start');
39 my $end = $class->condition_sql_option('end');
41 $start = "$start IS NULL OR cust_main.signupdate >=" .
42 str2time_sql . "($start)::timestamp" . str2time_sql_closing;
43 $end = "$end IS NULL OR cust_main.signupdate < 86400 + " .
44 str2time_sql . "($end)::timestamp" . str2time_sql_closing;
45 "($start) AND ($end)";