Skip to content

Commit

Permalink
Use the new ->IsSet method, rather than checking vs ->Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmv committed May 15, 2014
1 parent 5149153 commit b4c54fa
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 66 deletions.
2 changes: 1 addition & 1 deletion lib/RT/Action/CreateTickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ sub ParseLines {
eval {
$dateobj->Set( Format => 'iso', Value => $args{$date} );
};
if ($@ or $dateobj->Unix <= 0) {
if ($@ or not $dateobj->IsSet) {
$dateobj->Set( Format => 'unknown', Value => $args{$date} );
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Action/EscalatePriority.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ sub Prepare {

# If we don't have a due date, adjust the priority by one
# until we hit the final priority
if ($due->Unix() < 1) {
if (not $due->IsSet) {
if ( $self->TicketObj->Priority > $self->TicketObj->FinalPriority ){
$self->{'prio'} = ($self->TicketObj->Priority - 1);
return 1;
Expand Down
9 changes: 4 additions & 5 deletions lib/RT/Action/LinearEscalate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ sub Prepare {

my $ticket = $self->TicketObj;

my $due = $ticket->DueObj->Unix;
unless ( $due > 0 ) {
unless ( $ticket->DueObj->IsSet ) {
$RT::Logger->debug('Due is not set. Not escalating.');
return 1;
}
Expand All @@ -181,16 +180,16 @@ sub Prepare {
# now we know we have a due date. for every day that passes,
# increment priority according to the formula

my $starts = $ticket->StartsObj->Unix;
$starts = $ticket->CreatedObj->Unix unless $starts > 0;
my $now = time;
my $starts = $ticket->StartsObj->IsSet ? $ticket->StartsObj->Unix : $ticket->CreatedObj->Unix;
my $now = time;

# do nothing if we didn't reach starts or created date
if ( $starts > $now ) {
$RT::Logger->debug('Starts(Created) is in future. Not escalating.');
return 1;
}

my $due = $ticket->DueObj->Unix;
$due = $starts + 1 if $due <= $starts; # +1 to avoid div by zero

my $percent_complete = ($now-$starts)/($due - $starts);
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Condition/BeforeDue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ sub IsApplicable {
my $cur = RT::Date->new( RT->SystemUser );
$cur->SetToNow();
my $due = $self->TicketObj->DueObj;
return (undef) if $due->Unix <= 0;
return (undef) unless $due->IsSet;

my $diff = $due->Diff($cur);
if ( $diff >= 0 and $diff <= $elapse ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Condition/Overdue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ If the due date is before "now" return true

sub IsApplicable {
my $self = shift;
if ($self->TicketObj->DueObj->Unix > 0 and
if ($self->TicketObj->DueObj->IsSet and
$self->TicketObj->DueObj->Unix < time()) {
return(1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ sub AsString {
my $self = shift;
my %args = (@_);

return $self->loc("Not set") unless $self->Unix > 0;
return $self->loc("Not set") unless $self->IsSet;

my $format = RT->Config->Get( 'DateTimeFormat', $self->CurrentUser ) || 'DefaultFormat';
$format = { Format => $format } unless ref $format;
Expand Down
4 changes: 2 additions & 2 deletions lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ sub ProcessTicketReminders {
Format => 'unknown',
Value => $due,
);
if ( defined $DateObj->Unix
if ( $DateObj->IsSet
&& $DateObj->Unix != $reminder->DueObj->Unix )
{
( $status, $msg ) = $reminder->SetDue( $DateObj->ISO );
Expand Down Expand Up @@ -3429,7 +3429,7 @@ sub ProcessTicketDates {
);

my $obj = $field . "Obj";
if ( ( defined $DateObj->Unix )
if ( ( $DateObj->IsSet )
and ( $DateObj->Unix != $Ticket->$obj()->Unix() ) )
{
my $method = "Set$field";
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/SearchBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ sub _LimitCustomField {
} elsif ( $type =~ /^Date(?:Time)?$/ ) {
my $date = RT::Date->new( $self->CurrentUser );
$date->Set( Format => 'unknown', Value => $value );
if ( $date->Unix ) {
if ( $date->IsSet ) {
if (
$type eq 'Date'
# Heuristics to determine if a date, and not
Expand Down
2 changes: 1 addition & 1 deletion lib/RT/Ticket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,7 @@ sub _SetStatus {
if ( $args{SetStarted}
&& $args{Lifecycle}->IsInitial($old)
&& !$args{NewLifecycle}->IsInitial($args{Status})
&& !$raw_started->Unix) {
&& !$raw_started->IsSet) {
# Set the Started time to "now"
$self->_Set(
Field => 'Started',
Expand Down
4 changes: 2 additions & 2 deletions share/html/Approvals/Elements/PendingMyApproval
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
<input type="checkbox" class="checkbox" value="1" id="ShowDependent" name="ShowDependent" <% defined($ARGS{'ShowDependent'}) && $ARGS{'ShowDependent'} && qq[checked="checked"] |n%> />
<label for="ShowDependent"><&|/l&>Show requests awaiting other approvals</&></label><br />

<&|/l_unsafe, qq{<input size='15' class="datepicker" value='}.($created_before->Unix > 0 &&$created_before->ISO(Timezone => 'user'))."' name='CreatedBefore' id='CreatedBefore' />"&>Only show approvals for requests created before [_1]</&><br />
<&|/l_unsafe, qq{<input size='15' class="datepicker" value='}.($created_before->IsSet &&$created_before->ISO(Timezone => 'user'))."' name='CreatedBefore' id='CreatedBefore' />"&>Only show approvals for requests created before [_1]</&><br />

<&|/l_unsafe, qq{<input size='15' class="datepicker" value='}.( $created_after->Unix >0 && $created_after->ISO(Timezone => 'user'))."' name='CreatedAfter' id='CreatedAfter' />"&>Only show approvals for requests created after [_1]</&>
<&|/l_unsafe, qq{<input size='15' class="datepicker" value='}.( $created_after->IsSet && $created_after->ISO(Timezone => 'user'))."' name='CreatedAfter' id='CreatedAfter' />"&>Only show approvals for requests created after [_1]</&>
</&>

<%init>
Expand Down
2 changes: 1 addition & 1 deletion share/html/Elements/RT__Ticket/ColumnMap
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ $COLUMN_MAP = {
value => sub {
my $date = $_[0]->DueObj;
# Highlight the date if it was due in the past, and it's still active
if ( $date && $date->Unix > 0 && $date->Diff < 0 && $_[0]->QueueObj->IsActiveStatus($_[0]->Status)) {
if ( $date && $date->IsSet && $date->Diff < 0 && $_[0]->QueueObj->IsActiveStatus($_[0]->Status)) {
return (\'<span class="overdue">' , $date->AgeAsString , \'</span>');
} else {
return $date->AgeAsString;
Expand Down
2 changes: 1 addition & 1 deletion share/html/Elements/ShowReminders
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ my $i =0;
while ( my $reminder = $reminders->Next ) {
$i++;
my $dueobj = $reminder->DueObj;
my $overdue = $dueobj->Unix > 0 && $dueobj->Diff < 0 ? 1 : 0;
my $overdue = $dueobj->IsSet && $dueobj->Diff < 0 ? 1 : 0;

my $targets = RT::Tickets->new($session{'CurrentUser'});
$targets->{'allow_deleted_search'} = 1;
Expand Down
2 changes: 1 addition & 1 deletion share/html/Elements/ValidateCustomFields
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ while ( my $CF = $CustomFields->Next ) {
Value => $_,
($CF->Type eq "Date" ? (Timezone => 'utc') : ())
);
$DateObj->Unix > 0
$DateObj->IsSet
} @values;
}
push @values, '' unless @values;
Expand Down
4 changes: 2 additions & 2 deletions share/html/NoAuth/iCal/dhandler
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ $feed->add_properties('method' => ['publish']);
$feed->add_properties('prodid' => ["-//" . RT->Config->Get('rtname') ."//"]);

while (my $t = $tickets->Next) {
next unless $t->DueObj->Unix > 0;
next unless $t->DueObj->IsSet;

my $starttime = $t->StartsObj->Unix > 0 ? $t->StartsObj : $t->CreatedObj;
my $starttime = $t->StartsObj->IsSet ? $t->StartsObj : $t->CreatedObj;

my $url;
if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
Expand Down
2 changes: 1 addition & 1 deletion share/html/Ticket/Create.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
Status TimeLeft/;

$clone->{$_} = $CloneTicketObj->$_->AsString
for grep { $CloneTicketObj->$_->Unix }
for grep { $CloneTicketObj->$_->IsSet }
map { $_ . "Obj" } qw/Starts Started Due Resolved/;

my $get_link_value = sub {
Expand Down
2 changes: 1 addition & 1 deletion share/html/Ticket/Elements/Reminders
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ $Ticket
$Index
</%args>
% my $dueobj = $Reminder->DueObj;
% my $overdue = $dueobj->Unix > 0 && $dueobj->Diff < 0 ? 1 : 0;
% my $overdue = $dueobj->IsSet && $dueobj->Diff < 0 ? 1 : 0;
<tr class="<% $Index%2 ? 'oddline' : 'evenline' %>" id="reminder-<% $Reminder->id %>">

<td class="collection-as-table">
Expand Down
2 changes: 1 addition & 1 deletion share/html/Ticket/Elements/ShowDates
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<tr class="date due">
<td class="label"><&|/l&>Due</&>:</td>\
% my $due = $Ticket->DueObj;
% if ( $due && $due->Unix > 0 && $due->Diff < 0 ) {
% if ( $due && $due->IsSet && $due->Diff < 0 ) {
<td class="value"><span class="overdue"><% $due->AsString %></span></td>
% } else {
<td class="value"><% $due->AsString %></td>
Expand Down
2 changes: 1 addition & 1 deletion share/html/m/ticket/create
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if ($CloneTicket) {
Status TimeLeft/;

$clone->{$_} = $CloneTicketObj->$_->AsString
for grep { $CloneTicketObj->$_->Unix }
for grep { $CloneTicketObj->$_->IsSet }
map { $_ . "Obj" } qw/Starts Started Due Resolved/;

my $get_link_value = sub {
Expand Down
2 changes: 1 addition & 1 deletion share/html/m/ticket/show
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ my $print_value = sub {
<div class="entry">
<div class="label date due"><&|/l&>Due</&>:</div>
% my $due = $Ticket->DueObj;
% if ( $due && $due->Unix > 0 && $due->Diff < 0 ) {
% if ( $due && $due->IsSet && $due->Diff < 0 ) {
<div class="value date due"><span class="overdue"><% $due->AsString %></span></div>
% } else {
<div class="value date due"><% $due->AsString %></div>
Expand Down
18 changes: 9 additions & 9 deletions t/api/date.t
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ warning_like
{ # bad format
my $date = RT::Date->new(RT->SystemUser);
$date->Set( Format => 'bad' );
is($date->Unix, 0, "bad format");
ok(!$date->IsSet, "bad format");
} qr{Unknown Date format: bad};


Expand Down Expand Up @@ -269,7 +269,7 @@ my $year = (localtime(time))[5] + 1900;
warning_like {
$date->Set(Format => 'ISO', Value => 'weird date');
} qr/Couldn't parse date 'weird date' as a ISO format/;
is($date->Unix, 0, "date was wrong => unix == 0");
ok(!$date->IsSet, "date was wrong => unix == 0");

# XXX: ISO format has more feature than we suport
# http://www.cl.cam.ac.uk/~mgk25/iso-time.html
Expand Down Expand Up @@ -301,15 +301,15 @@ my $year = (localtime(time))[5] + 1900;
warning_like {
$date->Set(Format => 'ISO', Value => '2005-13-28 15:10:00');
} qr/Invalid date/;
is($date->Unix, 0, "wrong month value");
ok(!$date->IsSet, "wrong month value");

warning_like {
$date->Set(Format => 'ISO', Value => '2005-00-28 15:10:00');
} qr/Invalid date/;
is($date->Unix, 0, "wrong month value");
ok(!$date->IsSet, "wrong month value");

$date->Set(Format => 'ISO', Value => '1960-01-28 15:10:00');
is($date->Unix, 0, "too old, we don't support");
ok(!$date->IsSet, "too old, we don't support");
}

{ # set+datemanip format(Time::ParseDate)
Expand All @@ -334,7 +334,7 @@ my $year = (localtime(time))[5] + 1900;
warnings_like {
$date->Set(Format => 'unknown', Value => 'weird date');
} qr{Couldn't parse date 'weird date' by Time::ParseDate};
is($date->Unix, 0, "date was wrong");
ok(!$date->IsSet, "date was wrong");

RT->Config->Set( Timezone => 'Europe/Moscow' );
$date->Set(Format => 'unknown', Value => '2005-11-28 15:10:00');
Expand Down Expand Up @@ -586,13 +586,13 @@ my $year = (localtime(time))[5] + 1900;
# set unknown format: edge cases
my $date = RT::Date->new(RT->SystemUser);
$date->Set( Value => 0, Format => 'unknown' );
is( $date->Unix(), 0, "unix is 0 with Value => 0, Format => 'unknown'" );
ok( !$date->IsSet, "unix is 0 with Value => 0, Format => 'unknown'" );

$date->Set( Value => '', Format => 'unknown' );
is( $date->Unix(), 0, "unix is 0 with Value => '', Format => 'unknown'" );
ok( !$date->IsSet, "unix is 0 with Value => '', Format => 'unknown'" );

$date->Set( Value => ' ', Format => 'unknown' );
is( $date->Unix(), 0, "unix is 0 with Value => ' ', Format => 'unknown'" );
ok( !$date->IsSet, "unix is 0 with Value => ' ', Format => 'unknown'" );
}

#TODO: AsString
Expand Down
2 changes: 1 addition & 1 deletion t/api/ticket.t
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ok( $t->Create(Queue => 'General', Due => '2002-05-21 00:00:00', ReferredToBy =>
ok ( my $id = $t->Id, "Got ticket id");
like ($t->RefersTo->First->Target , qr/fsck.com/, "Got refers to");
like ($t->ReferredToBy->First->Base , qr/cpan.org/, "Got referredtoby");
is ($t->ResolvedObj->Unix, 0, "It hasn't been resolved - ". $t->ResolvedObj->Unix);
ok (!$t->ResolvedObj->IsSet, "It hasn't been resolved");


}
Expand Down
Loading

0 comments on commit b4c54fa

Please sign in to comment.