[Rt-commit] rt branch, no-prototype, updated. rt-3.8.8-200-g5954df6

? sunnavy sunnavy at bestpractical.com
Wed Aug 11 09:07:29 EDT 2010


The branch, no-prototype has been updated
       via  5954df6614a1af462a2fcaadd7b7c19632968133 (commit)
      from  db9376364bfc743ff498aac5d815bcb387ba091c (commit)

Summary of changes:
 lib/RT/CustomField_Overlay.pm                      |   34 +++-
 lib/RT/Interface/Web.pm                            |    3 +
 lib/RT/Record.pm                                   |   32 +++-
 lib/RT/Tickets_Overlay.pm                          |  219 +++++++++++-------
 .../Elements/{Checkbox => EditCustomFieldDate}     |   29 ++--
 .../Elements/{Checkbox => EditCustomFieldDateTime} |   29 ++--
 share/html/Elements/SelectDate                     |    3 +
 .../{ShowCustomFieldText => ShowCustomFieldDate}   |   15 +-
 ...ShowCustomFieldText => ShowCustomFieldDateTime} |   15 +-
 share/html/Search/Elements/PickCFs                 |   50 +++--
 t/api/cf_date_search.t                             |  119 ++++++++++
 t/api/cf_datetime_search.t                         |  141 ++++++++++++
 t/web/cf_date.t                                    |  192 ++++++++++++++++
 t/web/cf_datetime.t                                |  238 ++++++++++++++++++++
 14 files changed, 976 insertions(+), 143 deletions(-)
 copy share/html/Elements/{Checkbox => EditCustomFieldDate} (80%)
 mode change 100755 => 100644
 copy share/html/Elements/{Checkbox => EditCustomFieldDateTime} (81%)
 mode change 100755 => 100644
 copy share/html/Elements/{ShowCustomFieldText => ShowCustomFieldDate} (87%)
 copy share/html/Elements/{ShowCustomFieldText => ShowCustomFieldDateTime} (88%)
 create mode 100644 t/api/cf_date_search.t
 create mode 100644 t/api/cf_datetime_search.t
 create mode 100644 t/web/cf_date.t
 create mode 100644 t/web/cf_datetime.t

- Log -----------------------------------------------------------------
commit 5954df6614a1af462a2fcaadd7b7c19632968133
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Aug 11 20:30:19 2010 +0800

    merge cf-date to get cf seperate date/datetime

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index e156227..28114d8 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -97,6 +97,16 @@ our %FieldTypes = (
         'Enter one value with autocompletion',            # loc
         'Enter up to [_1] values with autocompletion',    # loc
     ],
+    Date => [
+        'Select multiple dates',	# loc
+        'Select date',			# loc
+        'Select up to [_1] dates',	# loc
+    ],
+    DateTime => [
+        'Select multiple datetimes',	# loc
+        'Select datetime',			# loc
+        'Select up to [_1] datetimes',	# loc
+    ],
 );
 
 
@@ -830,7 +840,7 @@ Returns an array of all possible composite values for custom fields.
 
 sub TypeComposites {
     my $self = shift;
-    return grep !/(?:[Tt]ext|Combobox)-0/, map { ("$_-1", "$_-0") } $self->Types;
+    return grep !/(?:[Tt]ext|Combobox|Date|DateTime)-0/, map { ("$_-1", "$_-0") } $self->Types;
 }
 
 =head2 SetLookupType
@@ -1161,6 +1171,28 @@ sub AddValueForObject {
             $extra_values--;
         }
     }
+    # For date, we need to store Content as ISO date
+    if ( $self->Type eq 'DateTime' ) {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'unknown',
+            Value  => $args{'Content'},
+        );
+        $args{'Content'} = $DateObj->ISO;
+    }
+    elsif ( $self->Type eq 'Date' ) {
+
+        # in case user input date with time, let's omit it by setting timezone
+        # to utc so "hour" won't affect "day"
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format   => 'unknown',
+            Value    => $args{'Content'},
+            Timezone => 'UTC',
+        );
+        $args{'Content'} = $DateObj->Date( Timezone => 'UTC' );
+    }
+
     my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
     my $val    = $newval->Create(
         ObjectType   => ref($obj),
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 7e5f975..be73cbe 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1737,6 +1737,9 @@ sub _ProcessObjectCustomFieldUpdates {
                 $values_hash{$val} = 1 if $val;
             }
 
+            # For Date Cfs, @values is empty when there is no changes (no datas in form input)
+            return @results if ( $cf->Type =~ /^Date(?:Time)?$/ && ! @values );
+
             $cf_values->RedoSearch;
             while ( my $cf_value = $cf_values->Next ) {
                 next if $values_hash{ $cf_value->id };
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 9ecad76..90854b5 100755
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1713,6 +1713,26 @@ sub _AddCustomFieldValue {
         }
 
         my $new_content = $new_value->Content;
+
+        # For datetime, we need to display them in "human" format in result message
+        #XXX TODO how about date without time?
+        if ($cf->Type eq 'DateTime') {
+            my $DateObj = new RT::Date( $self->CurrentUser );
+            $DateObj->Set(
+                Format => 'ISO',
+                Value  => $new_content,
+            );
+            $new_content = $DateObj->AsString;
+
+            if ( defined $old_content && length $old_content ) {
+                $DateObj->Set(
+                    Format => 'ISO',
+                    Value  => $old_content,
+                );
+                $old_content = $DateObj->AsString;
+            }
+        }
+
         unless ( defined $old_content && length $old_content ) {
             return ( $new_value_id, $self->loc( "[_1] [_2] added", $cf->Name, $new_content ));
         }
@@ -1801,11 +1821,21 @@ sub DeleteCustomFieldValue {
         return ( 0, $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
     }
 
+    my $old_value = $TransactionObj->OldValue;
+    # For datetime, we need to display them in "human" format in result message
+    if ( $cf->Type eq 'DateTime' ) {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'ISO',
+            Value  => $old_value,
+        );
+        $old_value = $DateObj->AsString;
+    }
     return (
         $TransactionId,
         $self->loc(
             "[_1] is no longer a value for custom field [_2]",
-            $TransactionObj->OldValue, $cf->Name
+            $old_value, $cf->Name
         )
     );
 }
diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index e8d350d..31d612f 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -1423,111 +1423,164 @@ sub _CustomFieldLimit {
                 %rest
             );
         }
-        elsif ( $op eq '=' || $op eq '!=' || $op eq '<>' ) {
-            unless ( length( Encode::encode_utf8($value) ) > 255 ) {
+        else {
+            my $cf = RT::CustomField->new( $self->CurrentUser );
+            $cf->Load($field);
+
+            # need special treatment for Date
+            if ( $cf->Type =~ /^Date(Time)?$/ ) {
+                my $is_datetime = $1 ? 1 : 0;
+                if ( $is_datetime && $op eq '=' ) {
+
+               # if we're specifying =, that means we want everything on a
+               # particular single day.  in the database, we need to check for >
+               # and < the edges of that day.
+
+                    my $date = RT::Date->new( $self->CurrentUser );
+                    $date->Set( Format => 'unknown', Value => $value );
+                    $date->SetToMidnight( Timezone => 'server' );
+                    my $daystart = $date->ISO;
+                    $date->AddDay;
+                    my $dayend = $date->ISO;
+
+                    $self->_OpenParen;
+
+                    $self->_SQLLimit(
+                        ALIAS    => $TicketCFs,
+                        FIELD    => 'Content',
+                        OPERATOR => ">=",
+                        VALUE    => $daystart,
+                        %rest,
+                    );
+
+                    $self->_SQLLimit(
+                        ALIAS    => $TicketCFs,
+                        FIELD    => 'Content',
+                        OPERATOR => "<=",
+                        VALUE    => $dayend,
+                        %rest,
+                        ENTRYAGGREGATOR => 'AND',
+                    );
+
+                    $self->_CloseParen;
+                }
+                else {
+                    $self->_SQLLimit(
+                        ALIAS    => $TicketCFs,
+                        FIELD    => 'Content',
+                        OPERATOR => $op,
+                        VALUE    => $value,
+                        %rest,
+                    );
+                }
+            }
+            elsif ( $op eq '=' || $op eq '!=' || $op eq '<>' ) {
+                unless ( length( Encode::encode_utf8($value) ) > 255 ) {
+                    $self->_SQLLimit(
+                        ALIAS    => $TicketCFs,
+                        FIELD    => 'Content',
+                        OPERATOR => $op,
+                        VALUE    => $value,
+                        %rest
+                    );
+                }
+                else {
+                    $self->_OpenParen;
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'Content',
+                        OPERATOR        => '=',
+                        VALUE           => '',
+                        ENTRYAGGREGATOR => 'OR'
+                    );
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'Content',
+                        OPERATOR        => 'IS',
+                        VALUE           => 'NULL',
+                        ENTRYAGGREGATOR => 'OR'
+                    );
+                    $self->_CloseParen;
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'LargeContent',
+                        OPERATOR        => $fix_op->($op),
+                        VALUE           => $value,
+                        ENTRYAGGREGATOR => 'AND',
+                    );
+                }
+            }
+            else {
                 $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => $op,
-                    VALUE      => $value,
+                    ALIAS    => $TicketCFs,
+                    FIELD    => 'Content',
+                    OPERATOR => $op,
+                    VALUE    => $value,
                     %rest
                 );
-            } else {
+
+                $self->_OpenParen;
                 $self->_OpenParen;
                 $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => '=',
-                    VALUE      => '',
+                    ALIAS           => $TicketCFs,
+                    FIELD           => 'Content',
+                    OPERATOR        => '=',
+                    VALUE           => '',
                     ENTRYAGGREGATOR => 'OR'
                 );
                 $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => 'IS',
-                    VALUE      => 'NULL',
+                    ALIAS           => $TicketCFs,
+                    FIELD           => 'Content',
+                    OPERATOR        => 'IS',
+                    VALUE           => 'NULL',
                     ENTRYAGGREGATOR => 'OR'
                 );
                 $self->_CloseParen;
                 $self->_SQLLimit(
-                    ALIAS => $TicketCFs,
-                    FIELD => 'LargeContent',
-                    OPERATOR => $fix_op->($op),
-                    VALUE => $value,
+                    ALIAS           => $TicketCFs,
+                    FIELD           => 'LargeContent',
+                    OPERATOR        => $fix_op->($op),
+                    VALUE           => $value,
                     ENTRYAGGREGATOR => 'AND',
                 );
+                $self->_CloseParen;
             }
-        }
-        else {
-            $self->_SQLLimit(
-                ALIAS      => $TicketCFs,
-                FIELD      => 'Content',
-                OPERATOR   => $op,
-                VALUE      => $value,
-                %rest
-            );
-
-            $self->_OpenParen;
-            $self->_OpenParen;
-            $self->_SQLLimit(
-                ALIAS      => $TicketCFs,
-                FIELD      => 'Content',
-                OPERATOR   => '=',
-                VALUE      => '',
-                ENTRYAGGREGATOR => 'OR'
-            );
-            $self->_SQLLimit(
-                ALIAS      => $TicketCFs,
-                FIELD      => 'Content',
-                OPERATOR   => 'IS',
-                VALUE      => 'NULL',
-                ENTRYAGGREGATOR => 'OR'
-            );
             $self->_CloseParen;
+
+            # XXX: if we join via CustomFields table then
+            # because of order of left joins we get NULLs in
+            # CF table and then get nulls for those records
+            # in OCFVs table what result in wrong results
+            # as decifer method now tries to load a CF then
+            # we fall into this situation only when there
+            # are more than one CF with the name in the DB.
+            # the same thing applies to order by call.
+            # TODO: reorder joins T <- OCFVs <- CFs <- OCFs if
+            # we want treat IS NULL as (not applies or has
+            # no value)
             $self->_SQLLimit(
-                ALIAS => $TicketCFs,
-                FIELD => 'LargeContent',
-                OPERATOR => $fix_op->($op),
-                VALUE => $value,
+                ALIAS           => $CFs,
+                FIELD           => 'Name',
+                OPERATOR        => 'IS NOT',
+                VALUE           => 'NULL',
+                QUOTEVALUE      => 0,
                 ENTRYAGGREGATOR => 'AND',
-            );
+            ) if $CFs;
             $self->_CloseParen;
-        }
-        $self->_CloseParen;
 
-        # XXX: if we join via CustomFields table then
-        # because of order of left joins we get NULLs in
-        # CF table and then get nulls for those records
-        # in OCFVs table what result in wrong results
-        # as decifer method now tries to load a CF then
-        # we fall into this situation only when there
-        # are more than one CF with the name in the DB.
-        # the same thing applies to order by call.
-        # TODO: reorder joins T <- OCFVs <- CFs <- OCFs if
-        # we want treat IS NULL as (not applies or has
-        # no value)
-        $self->_SQLLimit(
-            ALIAS      => $CFs,
-            FIELD      => 'Name',
-            OPERATOR   => 'IS NOT',
-            VALUE      => 'NULL',
-            QUOTEVALUE => 0,
-            ENTRYAGGREGATOR => 'AND',
-        ) if $CFs;
-        $self->_CloseParen;
+            if ($negative_op) {
+                $self->_SQLLimit(
+                    ALIAS           => $TicketCFs,
+                    FIELD           => $column || 'Content',
+                    OPERATOR        => 'IS',
+                    VALUE           => 'NULL',
+                    QUOTEVALUE      => 0,
+                    ENTRYAGGREGATOR => 'OR',
+                );
+            }
 
-        if ($negative_op) {
-            $self->_SQLLimit(
-                ALIAS           => $TicketCFs,
-                FIELD           => $column || 'Content',
-                OPERATOR        => 'IS',
-                VALUE           => 'NULL',
-                QUOTEVALUE      => 0,
-                ENTRYAGGREGATOR => 'OR',
-            );
+            $self->_CloseParen;
         }
-
-        $self->_CloseParen;
     }
     else {
         $cfkey .= '.'. $self->{'_sql_multiple_cfs_index'}++;
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/EditCustomFieldDate
old mode 100755
new mode 100644
similarity index 68%
copy from share/html/Elements/SelectDate
copy to share/html/Elements/EditCustomFieldDate
index c37c23f..b6e10a0
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/EditCustomFieldDate
@@ -1,8 +1,8 @@
 %# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
 %#                                          <jesse at bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -24,7 +24,7 @@
 %# along with this program; if not, write to the Free Software
 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 %# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# http://www.gnu.org/copyleft/gpl.html.
 %# 
 %# 
 %# CONTRIBUTION SUBMISSION POLICY:
@@ -45,30 +45,18 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<input type="text" class="ui-datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
-<%init>
-unless ((defined $Default) or 
-	($current <= 0)) {
-	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-                                            localtime($current);
-        $Default = sprintf("%04d-%02d-%02d %02d:%02d",                         
-                           $year+1900,$mon+1,$mday,                            
-                           $hour,$min);   
-}
-$Value = $Value || $Default;
-
-unless ($Name) {
-	$Name = $menu_prefix. "_Date";
-}
-</%init>
-
-<%args>
+% my $name = $NamePrefix.$CustomField->Id.'-Values';
+<& /Elements/SelectDate, Name => "$name", current => 0, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0)%>)
 
-$ShowTime => 1
-$menu_prefix=>''
-$current=>time
-$Default => ''
-$Value => ''
-$Name => undef
-$Size => 16
-</%args>
+<%INIT>
+my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+$DateObj->Set( Format => 'unknown', Value => $Default );
+</%INIT>
+<%ARGS>
+$Object => undef
+$CustomField => undef
+$NamePrefix => undef
+$Default => undef
+$Values => undef
+$MaxValues => 1
+</%ARGS>
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/EditCustomFieldDateTime
old mode 100755
new mode 100644
similarity index 68%
copy from share/html/Elements/SelectDate
copy to share/html/Elements/EditCustomFieldDateTime
index c37c23f..9df469f
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/EditCustomFieldDateTime
@@ -1,8 +1,8 @@
 %# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
 %#                                          <jesse at bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -24,7 +24,7 @@
 %# along with this program; if not, write to the Free Software
 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 %# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# http://www.gnu.org/copyleft/gpl.html.
 %# 
 %# 
 %# CONTRIBUTION SUBMISSION POLICY:
@@ -45,30 +45,18 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<input type="text" class="ui-datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
-<%init>
-unless ((defined $Default) or 
-	($current <= 0)) {
-	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-                                            localtime($current);
-        $Default = sprintf("%04d-%02d-%02d %02d:%02d",                         
-                           $year+1900,$mon+1,$mday,                            
-                           $hour,$min);   
-}
-$Value = $Value || $Default;
-
-unless ($Name) {
-	$Name = $menu_prefix. "_Date";
-}
-</%init>
-
-<%args>
+% my $name = $NamePrefix.$CustomField->Id.'-Values';
+<& /Elements/SelectDate, Name => "$name", current => 0 &> (<%$DateObj->AsString%>)
 
-$ShowTime => 1
-$menu_prefix=>''
-$current=>time
-$Default => ''
-$Value => ''
-$Name => undef
-$Size => 16
-</%args>
+<%INIT>
+my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+$DateObj->Set( Format => 'ISO', Value => $Default );
+</%INIT>
+<%ARGS>
+$Object => undef
+$CustomField => undef
+$NamePrefix => undef
+$Default => undef
+$Values => undef
+$MaxValues => 1
+</%ARGS>
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/SelectDate
index c37c23f..32c3e57 100755
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/SelectDate
@@ -60,6 +60,9 @@ $Value = $Value || $Default;
 unless ($Name) {
 	$Name = $menu_prefix. "_Date";
 }
+
+my $escaped_name = $Name;
+$escaped_name =~ s/'/\\'/g;
 </%init>
 
 <%args>
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/ShowCustomFieldDate
old mode 100755
new mode 100644
similarity index 70%
copy from share/html/Elements/SelectDate
copy to share/html/Elements/ShowCustomFieldDate
index c37c23f..3a80c0a
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/ShowCustomFieldDate
@@ -1,8 +1,8 @@
 %# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
 %#                                          <jesse at bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -45,30 +45,13 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<input type="text" class="ui-datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
-<%init>
-unless ((defined $Default) or 
-	($current <= 0)) {
-	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-                                            localtime($current);
-        $Default = sprintf("%04d-%02d-%02d %02d:%02d",                         
-                           $year+1900,$mon+1,$mday,                            
-                           $hour,$min);   
-}
-$Value = $Value || $Default;
-
-unless ($Name) {
-	$Name = $menu_prefix. "_Date";
-}
-</%init>
-
-<%args>
-
-$ShowTime => 1
-$menu_prefix=>''
-$current=>time
-$Default => ''
-$Value => ''
-$Name => undef
-$Size => 16
-</%args>
+<%INIT>
+ my $content = $Object->Content;
+ my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+ $DateObj->Set( Format => 'unknown', Value => $content );
+ $content = $DateObj->AsString(Time => 0);
+</%INIT>
+<%$content|n%>
+<%ARGS>
+$Object
+</%ARGS>
diff --git a/share/html/Elements/SelectDate b/share/html/Elements/ShowCustomFieldDateTime
old mode 100755
new mode 100644
similarity index 70%
copy from share/html/Elements/SelectDate
copy to share/html/Elements/ShowCustomFieldDateTime
index c37c23f..4e8ad67
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/ShowCustomFieldDateTime
@@ -1,8 +1,8 @@
 %# BEGIN BPS TAGGED BLOCK {{{
 %# 
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
 %#                                          <jesse at bestpractical.com>
 %# 
 %# (Except where explicitly superseded by other copyright notices)
@@ -45,30 +45,13 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<input type="text" class="ui-datepicker<% $ShowTime ? ' withtime' : '' %>" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
-<%init>
-unless ((defined $Default) or 
-	($current <= 0)) {
-	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-                                            localtime($current);
-        $Default = sprintf("%04d-%02d-%02d %02d:%02d",                         
-                           $year+1900,$mon+1,$mday,                            
-                           $hour,$min);   
-}
-$Value = $Value || $Default;
-
-unless ($Name) {
-	$Name = $menu_prefix. "_Date";
-}
-</%init>
-
-<%args>
-
-$ShowTime => 1
-$menu_prefix=>''
-$current=>time
-$Default => ''
-$Value => ''
-$Name => undef
-$Size => 16
-</%args>
+<%INIT>
+ my $content = $Object->Content;
+ my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+ $DateObj->Set( Format => 'ISO', Value => $content );
+ $content = $DateObj->AsString;
+</%INIT>
+<%$content|n%>
+<%ARGS>
+$Object
+</%ARGS>
diff --git a/share/html/Search/Elements/PickCFs b/share/html/Search/Elements/PickCFs
index ba25cde..65d58f3 100644
--- a/share/html/Search/Elements/PickCFs
+++ b/share/html/Search/Elements/PickCFs
@@ -78,20 +78,42 @@ while ( my $CustomField = $CustomFields->Next ) {
     my %line;
     $line{'Name'} = "'CF.{" . $CustomField->Name . "}'";
     $line{'Field'} = $CustomField->Name;
-    $line{'Op'} = {
-        Type => 'component',
-        Path => '/Elements/SelectCustomFieldOperator',
-        Arguments => { True => loc("is"),
-                       False => loc("isn't"),
-                       TrueVal=> '=',
-                       FalseVal => '!=',
-                     },
-    };
-    $line{'Value'} = {
-        Type => 'component',
-        Path => '/Elements/SelectCustomFieldValue',
-        Arguments => { CustomField => $CustomField },
-    };
+
+    # Op
+    if ($CustomField->Type =~ /^Date(Time)?$/ ) {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectDateRelation',
+            Arguments => {},
+        };
+    } else {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectCustomFieldOperator',
+            Arguments => { True => loc("is"),
+                           False => loc("isn't"),
+                           TrueVal=> '=',
+                           FalseVal => '!=',
+                         },
+        };
+    }
+
+    # Value
+    if ($CustomField->Type =~ /^Date(Time)?$/) {
+        my $is_datetime = $1 ? 1 : 0;
+        $line{'Value'} = {
+            Type => 'component',
+            Path => '/Elements/SelectDate',
+            Arguments => { $is_datetime ? ( ShowTime => 0 ) : (), },
+        };
+    } else {
+        $line{'Value'} = {
+            Type => 'component',
+            Path => '/Elements/SelectCustomFieldValue',
+            Arguments => { CustomField => $CustomField },
+        };
+    }
+
     push @lines, \%line;
 }
 
diff --git a/t/api/cf_date_search.t b/t/api/cf_date_search.t
new file mode 100644
index 0000000..15abd70
--- /dev/null
+++ b/t/api/cf_date_search.t
@@ -0,0 +1,119 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use RT::Test tests => 13;
+
+my $q = RT::Queue->new($RT::SystemUser);
+ok( $q->Create( Name => 'DateCFTest' . $$ ), 'create queue' );
+
+my $cf = RT::CustomField->new($RT::SystemUser);
+ok(
+    $cf->Create(
+        Name       => 'date-' . $$,
+        Type       => 'Date',
+        MaxValues  => 1,
+        LookupType => RT::Ticket->CustomFieldLookupType,
+    ),
+    'create cf date'
+);
+ok( $cf->AddToObject($q), 'date cf apply to queue' );
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+
+ok(
+    $ticket->Create(
+        Queue                    => $q->id,
+        Subject                  => 'Test',
+        'CustomField-' . $cf->id => '2010-05-04',
+    ),
+    'create ticket with cf set to 2010-05-04'
+);
+
+is( $ticket->CustomFieldValues->First->Content, '2010-05-04', 'date in db is' );
+
+{
+
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-05-04',
+    );
+    is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04' );
+
+}
+
+{
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '>',
+        VALUE       => '2010-05-03',
+    );
+
+    is( $tickets->Count, 1, 'found ticket with > 2010-05-03' );
+}
+
+{
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '<',
+        VALUE       => '2010-05-05',
+    );
+
+    is( $tickets->Count, 1, 'found ticket with < 2010-05-05' );
+}
+
+{
+
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-05-05',
+    );
+
+    is( $tickets->Count, 0, 'did not find the ticket with = 2010-05-05' );
+}
+
+{
+
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '<',
+        VALUE       => '2010-05-03',
+    );
+
+    is( $tickets->Count, 0, 'did not find the ticket with < 2010-05-03' );
+}
+
+{
+
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '>',
+        VALUE       => '2010-05-05',
+    );
+
+    is( $tickets->Count, 0, 'did not find the ticket with > 2010-05-05' );
+}
+
+$ticket = RT::Ticket->new($RT::SystemUser);
+
+ok(
+    $ticket->Create(
+        Queue                    => $q->id,
+        Subject                  => 'Test',
+        'CustomField-' . $cf->id => '2010-05-04 12:34:56',
+    ),
+    'create ticket with cf set to 2010-05-04 12:34:56'
+);
+
+is( $ticket->CustomFieldValues->First->Content,
+    '2010-05-04', 'date in db only has date' );
+
diff --git a/t/api/cf_datetime_search.t b/t/api/cf_datetime_search.t
new file mode 100644
index 0000000..d0884f4
--- /dev/null
+++ b/t/api/cf_datetime_search.t
@@ -0,0 +1,141 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use RT::Test tests => 14;
+RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00
+
+my $q = RT::Queue->new($RT::SystemUser);
+ok( $q->Create( Name => 'DateTimeCFTest' . $$ ), 'create queue' );
+
+my $cf = RT::CustomField->new($RT::SystemUser);
+ok(
+    $cf->Create(
+        Name       => 'datetime-' . $$,
+        Type       => 'DateTime',
+        MaxValues  => 1,
+        LookupType => RT::Ticket->CustomFieldLookupType,
+    ),
+    'create cf datetime'
+);
+ok( $cf->AddToObject($q), 'date cf apply to queue' );
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+
+ok(
+    $ticket->Create(
+        Queue                    => $q->id,
+        Subject                  => 'Test',
+        'CustomField-' . $cf->id => '2010-05-04 08:00:00',
+    ),
+    'create ticket with cf set to 2010-05-04 08:00:00( 2010-05-04 12:00:00 with UTC )'
+);
+
+is(
+    $ticket->CustomFieldValues->First->Content,
+    '2010-05-04 12:00:00',
+    'date in db is in timezone UTC'
+);
+
+{
+
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-05-04 12:00:00',    # this timezone is UTC
+    );
+
+    is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04 12:00:00' );
+}
+
+{
+
+    # TODO according to the code, if OPERATOR is '=', it means on that day
+    # this will test this behavior
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-05-04',
+    );
+
+    is( $tickets->Count, 1, 'found the ticket with rough date: 2010-05-04' );
+}
+
+{
+
+    # TODO according to the code, if OPERATOR is '=', it means on that day
+    # this will test this behavior
+    my $tickets = RT::Tickets->new($RT::SystemUser);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-05-05',
+    );
+
+    is( $tickets->Count, 0, 'did not find the ticket with wrong datetime: 2010-05-05' );
+}
+
+my $tickets = RT::Tickets->new( $RT::SystemUser );
+$tickets->UnLimit;
+while( my $ticket  = $tickets->Next ) {
+    $ticket->Delete();
+}
+
+{
+    ok(
+        $ticket->Create(
+            Queue                    => $q->id,
+            Subject                  => 'Test',
+            'CustomField-' . $cf->id => '2010-06-21 17:00:01',
+        ),
+'create ticket with cf set to 2010-06-21 17:00:01( 2010-06-21 21:00:01 with UTC )'
+    );
+
+    my $shanghai = RT::Test->load_or_create_user(
+        Name     => 'shanghai',
+        Timezone => 'Asia/Shanghai',
+    );
+
+    ok(
+        $shanghai->PrincipalObj->GrantRight(
+            Right  => 'SuperUser',
+            Object => $RT::System,
+        )
+    );
+
+    my $current_user = RT::CurrentUser->new($shanghai);
+    my $tickets      = RT::Tickets->new($current_user);
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-06-22',
+    );
+    is( $tickets->Count, 1, 'found the ticket with rough datetime: 2010-06-22' );
+
+    $tickets->UnLimit;
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '>',
+        VALUE       => '2010-06-21',
+    );
+    is( $tickets->Count, 1, 'found the ticket with > 2010-06-21' );
+
+    $tickets->UnLimit;
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '<',
+        VALUE       => '2010-06-23',
+    );
+    is( $tickets->Count, 1, 'found the ticket with < 2010-06-23' );
+
+    $tickets->UnLimit;
+    $tickets->LimitCustomField(
+        CUSTOMFIELD => $cf->id,
+        OPERATOR    => '=',
+        VALUE       => '2010-06-22 05:00:01',
+    );
+    is( $tickets->Count, 1, 'found the ticket with = 2010-06-22 01:00:01' );
+}
diff --git a/t/web/cf_date.t b/t/web/cf_date.t
new file mode 100644
index 0000000..7e34107
--- /dev/null
+++ b/t/web/cf_date.t
@@ -0,0 +1,192 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::Test tests => 35;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+my $root = RT::User->new($RT::SystemUser);
+ok( $root->Load('root'), 'load root user' );
+
+my $cf_name = 'test cf date';
+
+my $cfid;
+diag "Create a CF" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( text => 'Configuration' );
+    $m->title_is( q/RT Administration/, 'admin screen' );
+    $m->follow_link( text => 'Custom Fields' );
+    $m->title_is( q/Select a Custom Field/, 'admin-cf screen' );
+    $m->follow_link( text => 'Create' );
+    $m->submit_form(
+        form_name => "ModifyCustomField",
+        fields    => {
+            Name          => $cf_name,
+            TypeComposite => 'Date-1',
+            LookupType    => 'RT::Queue-RT::Ticket',
+        },
+    );
+    $m->content_like( qr/Object created/, 'created CF sucessfully' );
+    $cfid = $m->form_name('ModifyCustomField')->value('id');
+    ok $cfid, "found id of the CF in the form, it's #$cfid";
+}
+
+diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    $m->follow_link( text => 'Queues' );
+    $m->title_is( q/Admin queues/, 'admin-queues screen' );
+    $m->follow_link( text => 'General' );
+    $m->title_is( q/Editing Configuration for queue General/,
+        'admin-queue: general' );
+    $m->follow_link( text => 'Ticket Custom Fields' );
+    $m->title_is( q/Edit Custom Fields for General/,
+        'admin-queue: general cfid' );
+
+    $m->form_name('EditCustomFields');
+    $m->tick( "AddCustomField" => $cfid );
+    $m->click('UpdateCFs');
+
+    $m->content_like( qr/Object created/, 'TCF added to the queue' );
+}
+
+diag 'check valid inputs with various timezones in ticket create page'
+  if $ENV{'TEST_VERBOSE'};
+{
+    my ( $ticket, $id );
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields    => { Queue => 'General' },
+    );
+    $m->content_like( qr/Select date/, 'has cf field' );
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test 2010-05-04',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
+        },
+    );
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/, "created ticket $id" );
+
+    $ticket = RT::Ticket->new($RT::SystemUser);
+    $ticket->Load($id);
+    is( $ticket->CustomFieldValues($cfid)->First->Content,
+        '2010-05-04', 'date in db' );
+
+    $m->content_like( qr/test cf date:/, 'has no cf date field on the page' );
+    $m->content_like( qr/Tue May 04 2010/,
+        'has cf date value on the page' );
+}
+
+diag 'check search build page' if $ENV{'TEST_VERBOSE'};
+{
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+
+    $m->form_number(3);
+    my ($cf_op) =
+      $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
+    is_deeply(
+        [ $cf_op->possible_values ],
+        [ '<', '=', '>' ],
+        'right oprators'
+    );
+
+    my ($cf_field) =
+      $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-04'
+        },
+        button => 'DoSearch',
+    );
+
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+    $m->content_contains( '2010-05-04',     'got the right ticket' );
+    $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '<',
+            $cf_field->name => '2010-05-05'
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '>',
+            $cf_field->name => '2010-05-03',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-05',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '<',
+            $cf_field->name => '2010-05-03',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '>',
+            $cf_field->name => '2010-05-05',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 0 tickets', 'Found 0 tickets' );
+}
+
+diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
+{
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields    => { Queue => 'General' },
+    );
+    my $form = $m->form_name("TicketCreate");
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
+        },
+    );
+    $m->content_like( qr/Ticket \d+ created/,
+        "a ticket is created succesfully" );
+
+    $m->content_like( qr/test cf date:/, 'has no cf date field on the page' );
+    $m->content_unlike( qr/foodate/, 'invalid dates not set' );
+}
diff --git a/t/web/cf_datetime.t b/t/web/cf_datetime.t
new file mode 100644
index 0000000..2d11f53
--- /dev/null
+++ b/t/web/cf_datetime.t
@@ -0,0 +1,238 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::Test tests => 44;
+RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00
+
+my ($baseurl, $m) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+my $root = RT::User->new( $RT::SystemUser );
+ok( $root->Load('root'), 'load root user' );
+
+my $cf_name = 'test cf datetime';
+
+my $cfid;
+diag "Create a CF" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( text => 'Configuration' );
+    $m->title_is(q/RT Administration/, 'admin screen');
+    $m->follow_link( text => 'Custom Fields' );
+    $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
+    $m->follow_link( text => 'Create' );
+    $m->submit_form(
+        form_name => "ModifyCustomField",
+        fields => {
+            Name          => $cf_name,
+            TypeComposite => 'DateTime-1',
+            LookupType    => 'RT::Queue-RT::Ticket',
+        },
+    );
+    $m->content_like( qr/Object created/, 'created CF sucessfully' );
+    $cfid = $m->form_name('ModifyCustomField')->value('id');
+    ok $cfid, "found id of the CF in the form, it's #$cfid";
+}
+
+diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    $m->follow_link( text => 'Queues' );
+    $m->title_is(q/Admin queues/, 'admin-queues screen');
+    $m->follow_link( text => 'General' );
+    $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
+    $m->follow_link( text => 'Ticket Custom Fields' );
+    $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general cfid');
+
+    $m->form_name('EditCustomFields');
+    $m->tick( "AddCustomField" => $cfid );
+    $m->click('UpdateCFs');
+
+    $m->content_like( qr/Object created/, 'TCF added to the queue' );
+}
+
+diag 'check valid inputs with various timezones in ticket create page' if $ENV{'TEST_VERBOSE'};
+{
+    my ( $ticket, $id );
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
+    $m->content_like(qr/Select datetime/, 'has cf field');
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test 2010-05-04 13:00:01',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04 13:00:01',
+        },
+    );
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/,
+        "created ticket $id" );
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load($id);
+    is(
+        $ticket->CustomFieldValues($cfid)->First->Content,
+        '2010-05-04 17:00:01',
+        'date in db is in UTC'
+    );
+
+    $m->content_like(qr/test cf datetime:/, 'has no cf datetime field on the page');
+    $m->content_like(qr/Tue May 04 13:00:01 2010/, 'has cf datetime value on the page');
+
+    $root->SetTimezone( 'Asia/Shanghai' );
+    # interesting that $m->reload doesn't work
+    $m->get_ok( $m->uri );
+    $m->content_like(qr/Wed May 05 01:00:01 2010/, 'cf datetime value respects user timezone');
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test 2010-05-06 07:00:01',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-06 07:00:01',
+        },
+    );
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/,
+        "created ticket $id" );
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load($id);
+    is(
+        $ticket->CustomFieldValues($cfid)->First->Content,
+        '2010-05-05 23:00:01',
+        'date in db is in UTC'
+    );
+
+    $m->content_like(qr/test cf datetime:/, 'has no cf datetime field on the page');
+    $m->content_like(qr/Thu May 06 07:00:01 2010/, 'cf datetime input respects user timezone');
+    $root->SetTimezone( 'EST5EDT' ); # back to -04:00
+    $m->get_ok( $m->uri );
+    $m->content_like(qr/Wed May 05 19:00:01 2010/, 'cf datetime value respects user timezone');
+}
+
+
+diag 'check search build page' if $ENV{'TEST_VERBOSE'};
+{
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+
+    $m->form_number(3);
+    my ($cf_op) =
+      $m->find_all_inputs( type => 'option', name_regex => qr/test cf datetime/ );
+    is_deeply(
+        [ $cf_op->possible_values ],
+        [ '<', '=', '>' ],
+        'right oprators'
+    );
+
+    my ($cf_field) =
+      $m->find_all_inputs( type => 'text', name_regex => qr/test cf datetime/ );
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-04'
+        },
+        button => 'DoSearch',
+    );
+
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+    $m->content_contains( '2010-05-04',     'got the right ticket' );
+    $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );
+
+    my $shanghai = RT::Test->load_or_create_user(
+        Name     => 'shanghai',
+        Password => 'password',
+        Timezone => 'Asia/Shanghai',
+    );
+    ok( $shanghai->PrincipalObj->GrantRight(
+        Right  => 'SuperUser',
+        Object => $RT::System,
+    ));
+    $m->login( 'shanghai', 'password' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-05'
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '<',
+            $cf_field->name => '2010-05-06'
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 2 ticket', 'Found 2 ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '>',
+            $cf_field->name => '2010-05-03',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 2 tickets', 'Found 2 tickets' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-04 16:00:01',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+
+    $m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+    $m->form_number(3);
+    $m->submit_form(
+        fields => {
+            $cf_op->name    => '=',
+            $cf_field->name => '2010-05-05 01:00:01',
+        },
+        button => 'DoSearch',
+    );
+    $m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+}
+
+diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
+
+{
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
+    my $form = $m->form_name("TicketCreate");
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
+        },
+    );
+    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
+
+    $m->content_like(qr/test cf datetime:/, 'has no cf datetime field on the page');
+    $m->content_unlike(qr/foodate/, 'invalid dates not set');
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list