6 use RT::Test nodata => 1, tests => 14;
7 RT->Config->Set( 'Timezone' => 'EST5EDT' ); # -04:00
9 my $q = RT::Queue->new(RT->SystemUser);
10 ok( $q->Create( Name => 'DateTimeCFTest' . $$ ), 'create queue' );
12 my $cf = RT::CustomField->new(RT->SystemUser);
15 Name => 'datetime-' . $$,
18 LookupType => RT::Ticket->CustomFieldLookupType,
22 ok( $cf->AddToObject($q), 'date cf apply to queue' );
24 my $ticket = RT::Ticket->new(RT->SystemUser);
30 'CustomField-' . $cf->id => '2010-05-04 07:00:00',
32 'create ticket with cf set to 2010-05-04 07:00:00( 2010-05-04 11:00:00 with UTC )'
36 $ticket->CustomFieldValues->First->Content,
37 '2010-05-04 11:00:00',
38 'date in db is in timezone UTC'
43 my $tickets = RT::Tickets->new(RT->SystemUser);
44 $tickets->LimitCustomField(
45 CUSTOMFIELD => $cf->id,
47 VALUE => '2010-05-04 07:00:00', # this timezone is server
50 is( $tickets->Count, 1, 'found the ticket with exact date: 2010-05-04 07:00:00' );
55 # TODO according to the code, if OPERATOR is '=', it means on that day
56 # this will test this behavior
57 my $tickets = RT::Tickets->new(RT->SystemUser);
58 $tickets->LimitCustomField(
59 CUSTOMFIELD => $cf->id,
61 VALUE => '2010-05-04',
64 is( $tickets->Count, 1, 'found the ticket with rough date: 2010-05-04' );
69 # TODO according to the code, if OPERATOR is '=', it means on that day
70 # this will test this behavior
71 my $tickets = RT::Tickets->new(RT->SystemUser);
72 $tickets->LimitCustomField(
73 CUSTOMFIELD => $cf->id,
75 VALUE => '2010-05-05',
78 is( $tickets->Count, 0, 'did not find the ticket with wrong datetime: 2010-05-05' );
81 my $tickets = RT::Tickets->new( RT->SystemUser );
83 while( my $ticket = $tickets->Next ) {
92 'CustomField-' . $cf->id => '2010-06-21 17:00:01',
94 'create ticket with cf set to 2010-06-21 17:00:01( 2010-06-21 21:00:01 with UTC )'
97 my $shanghai = RT::Test->load_or_create_user(
99 Timezone => 'Asia/Shanghai',
103 $shanghai->PrincipalObj->GrantRight(
104 Right => 'SuperUser',
105 Object => $RT::System,
109 my $current_user = RT::CurrentUser->new($shanghai);
110 my $tickets = RT::Tickets->new($current_user);
111 $tickets->LimitCustomField(
112 CUSTOMFIELD => $cf->id,
114 VALUE => '2010-06-22',
116 is( $tickets->Count, 1, 'found the ticket with rough datetime: 2010-06-22' );
119 $tickets->LimitCustomField(
120 CUSTOMFIELD => $cf->id,
122 VALUE => '2010-06-21',
124 is( $tickets->Count, 1, 'found the ticket with > 2010-06-21' );
127 $tickets->LimitCustomField(
128 CUSTOMFIELD => $cf->id,
130 VALUE => '2010-06-23',
132 is( $tickets->Count, 1, 'found the ticket with < 2010-06-23' );
135 $tickets->LimitCustomField(
136 CUSTOMFIELD => $cf->id,
138 VALUE => '2010-06-22 05:00:01',
140 is( $tickets->Count, 1, 'found the ticket with = 2010-06-22 01:00:01' );