[Rt-commit] rt branch, 4.0/correct-date-cf-canonicalization, created. rt-4.0.7-62-ge77af85

Ruslan Zakirov ruz at bestpractical.com
Mon Feb 11 17:47:30 EST 2013


The branch, 4.0/correct-date-cf-canonicalization has been created
        at  e77af8532f5243036e4d518835c381e51cf0c519 (commit)

- Log -----------------------------------------------------------------
commit 0613c1a9ef74b3664ec3840f883055bde59aa8b5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Sep 19 23:33:20 2012 +0800

    date cf should be timezoneless
    
    we should show the same date no matter what date format is.
    
    see also #20856

diff --git a/share/html/Elements/ShowCustomFieldDate b/share/html/Elements/ShowCustomFieldDate
index 8c94c13..2bce717 100644
--- a/share/html/Elements/ShowCustomFieldDate
+++ b/share/html/Elements/ShowCustomFieldDate
@@ -48,8 +48,8 @@
 <%INIT>
  my $content = $Object->Content;
  my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
- $DateObj->Set( Format => 'unknown', Value => $content );
- $content = $DateObj->AsString(Time => 0);
+ $DateObj->Set( Format => 'unknown', Value => $content, Timezone => 'utc'  );
+ $content = $DateObj->AsString(Time => 0, Timezone => 'utc');
 </%INIT>
 <%$content|n%>
 <%ARGS>

commit 2a963a9515ece0bb8dc0895a56c1ead955671b66
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Feb 11 21:41:37 2013 +0400

    canonicalization of Date CF value is wrong, a test
    
    Timezone context is wrong. It only fails for relative
    dates like 'tomorrow'.

diff --git a/t/customfields/date.t b/t/customfields/date.t
new file mode 100644
index 0000000..0b8d1e9
--- /dev/null
+++ b/t/customfields/date.t
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+use Test::MockTime qw(set_fixed_time restore_time);
+
+use warnings;
+use strict;
+
+use RT::Test tests => undef;
+
+RT::Test->set_rights(
+    { Principal => 'Everyone', Right => [qw(
+        SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField
+    )] },
+);
+
+my $q = RT::Test->load_or_create_queue( Name => 'General' );
+ok $q && $q->id, 'loaded or created a queue';
+
+my $user_m = RT::Test->load_or_create_user( Name => 'moscow', Timezone => 'Europe/Moscow' );
+ok $user_m && $user_m->id;
+
+my $user_b = RT::Test->load_or_create_user( Name => 'boston', Timezone => 'America/New_York' );
+ok $user_b && $user_b->id;
+
+
+my $cf_name = 'A Date';
+my $cf;
+{
+    $cf = RT::CustomField->new(RT->SystemUser);
+    ok(
+        $cf->Create(
+            Name       => $cf_name,
+            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::CurrentUser->new( $user_m ) );
+    my ($id) = $ticket->Create(
+        Queue                   => $q->id,
+        Subject                 => 'Test',
+        'CustomField-'. $cf->id => '2013-02-11',
+    );
+    my $cf_value = $ticket->CustomFieldValues($cf_name)->First;
+    is( $cf_value->Content, '2013-02-11', 'correct value' );
+
+    $ticket = RT::Ticket->new( RT::CurrentUser->new( $user_b ) );
+    $ticket->Load($id);
+    is( $ticket->FirstCustomFieldValue($cf_name), '2013-02-11', 'correct value' );
+}
+
+# in moscow it's already Feb 11, so tomorrow is Feb 12
+set_fixed_time("2013-02-10T23:10:00Z");
+{
+    my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user_m ) );
+    my ($id) = $ticket->Create(
+        Queue                   => $q->id,
+        Subject                 => 'Test',
+        'CustomField-'. $cf->id => 'tomorrow',
+    );
+    my $cf_value = $ticket->CustomFieldValues($cf_name)->First;
+    is( $cf_value->Content, '2013-02-12', 'correct value' );
+
+    $ticket = RT::Ticket->new( RT::CurrentUser->new( $user_b ) );
+    $ticket->Load($id);
+    is( $ticket->FirstCustomFieldValue($cf_name), '2013-02-12', 'correct value' );
+}
+
+done_testing();

commit e77af8532f5243036e4d518835c381e51cf0c519
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Feb 11 21:45:17 2013 +0400

    parse Date in user's timezone
    
    Format it in the same timezone and we get what we need. This
    fixes parsing when relative value (like 'tomorrow') is used
    to set date. Previous code results in incorrect date if
    at the moment of parsing date in London is different from
    user's date.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 2002d4e..4bee252 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1539,9 +1539,9 @@ sub _CanonicalizeValueDate {
     my $DateObj = RT::Date->new( $self->CurrentUser );
     $DateObj->Set( Format   => 'unknown',
                    Value    => $args->{'Content'},
-                   Timezone => 'UTC',
+                   Timezone => 'user',
                  );
-    $args->{'Content'} = $DateObj->Date( Timezone => 'UTC' );
+    $args->{'Content'} = $DateObj->Date( Timezone => 'user' );
 }
 
 =head2 MatchPattern STRING

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


More information about the Rt-commit mailing list