[Bps-public-commit] rtx-calendar branch multiple-days-events updated. 1.05-24-g2839b2c

BPS Git Server git at git.bestpractical.com
Thu Sep 14 01:40:41 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtx-calendar".

The branch, multiple-days-events has been updated
       via  2839b2c0ac6ad4b2357b4aeb4037366cdb74ddce (commit)
      from  4a280196db87d18d53049b321c0d34ffe4f23790 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2839b2c0ac6ad4b2357b4aeb4037366cdb74ddce
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Wed Sep 13 22:38:25 2023 -0300

    Upgrade date objects ad methods to RT::Date
    
    Many of the date calculations of the calendar were done using different
    perl date and time modules. This was causing issues to present events in
    the user timezone.

diff --git a/html/Elements/CalendarEvent b/html/Elements/CalendarEvent
index 681b2fb..0cf0107 100644
--- a/html/Elements/CalendarEvent
+++ b/html/Elements/CalendarEvent
@@ -74,21 +74,34 @@ if ((!grep { $_ eq $TicketId } @$spanning_tickets_for_tomorrow )) {
 	:</strong> <% $subject%><br />
 	<br />
 
-%# logic taken from Ticket/Search/Results.tsv
-% foreach my $attr (@display_fields) {
-%    my $value;
-%
-%    if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
-%        $value = '-';
-%    } elsif ($attr =~ /CustomField\.\{(.*)\}$/) {
-%        my $cf = $1;
-%        $value = $Object->FirstCustomFieldValue($cf);
-%    } else {
-%        my $method = '$Object->'.$attr.'()';
-%        $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
-%        $value = eval $method;
-%        if ($@) {die "<b>Check your CalendarPopupFields config in etc/RT_SiteConfig.pm</b>.<br /><br />Failed to find \"$attr\" - ". $@};
-%    }
+<%perl>
+# logic taken from Ticket/Search/Results.tsv
+ foreach my $attr (@display_fields) {
+    my $value;
+
+    if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
+        $value = '-';
+    } elsif ($attr =~ /CustomField\.\{(.*)\}$/) {
+        my $cf = $1;
+        $value = $Object->FirstCustomFieldValue($cf);
+        my $cf_obj = RT::CustomField->new($RT::SystemUser);
+        $cf_obj->LoadByNameAndQueue(Queue => $Object->QueueObj->Id, Name => $cf);
+        if ($cf_obj->Type eq 'DateTime') {
+            my $date_value = RT::Date->new($RT::SystemUser);
+            $date_value->Set(Format => 'ISO', Value => $value);
+            $value = $date_value->ISO( Timezone => 'user' );
+        } elsif ($cf_obj->Type eq 'Date') {
+            my $date_value = RT::Date->new($RT::SystemUser);
+            $date_value->Set(Format => 'unknown', Value => $value);
+            $value = $date_value->ISO( Timezone => 'user' );
+        }
+    } else {
+        my $method = '$Object->'.$attr.'()';
+        $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
+        $value = eval $method;
+        if ($@) {die "<b>Check your CalendarPopupFields config in etc/RT_SiteConfig.pm</b>.<br /><br />Failed to find \"$attr\" - ". $@};
+    }
+</%perl>
 	<strong><&|/l&><% $label_of{$attr} %></&>:</strong> <% $value %><br />
 % }
 
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 9224fc2..5525b3d 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -34,14 +34,6 @@ sub LastDay {
     $day;
 }
 
-# we can't use RT::Date::Date because it uses gmtime
-# and we need localtime
-sub LocalDate {
-    my $ts = shift;
-    my ( $d, $m, $y ) = ( localtime($ts) )[ 3 .. 5 ];
-    sprintf "%4d-%02d-%02d", ( $y + 1900 ), ++$m, $d;
-}
-
 sub DatesClauses {
     my ( $Dates, $begin, $end ) = @_;
 
@@ -129,19 +121,19 @@ sub FindTickets {
             $current_date->Set(
                 Format => 'unknown',
                 Value => $starts_date,
-                Timezone => 'utc'
+                Timezone => 'user'
             );
             my $end_date_unix = RT::Date->new($CurrentUser);
             $end_date_unix->Set(
                 Format => 'unknown',
                 Value => $ends_date,
-                Timezone => 'utc'
+                Timezone => 'user'
             );
             $end_date_unix = $end_date_unix->Unix;
             my $first_day = 1;
             while ( $current_date->Unix <= $end_date_unix )
             {
-                my $dateindex = LocalDate( $current_date->Unix );
+                my $dateindex = $current_date->ISO( Time => 0, Timezone => 'user' );
 
                 push @{ $TicketsSpanningDays{$dateindex} }, $Ticket->id
                     unless $first_day
@@ -191,10 +183,10 @@ sub _GetDate {
         } else {
             $DateObj->Set( Format => 'ISO', Value => $CFDateValue );
         }
-        return LocalDate( $DateObj->Unix );
+        return $DateObj->ISO( Time => 0, Timezone => 'user' );
     } else {
         my $DateObj = $date_field . "Obj";
-        return LocalDate( $Ticket->$DateObj->Unix );
+        return $Ticket->$DateObj->ISO( Time => 0, Timezone => 'user' );
     }
 }
 
@@ -263,7 +255,7 @@ CALENDAR_ICON:
             $ComparedDate =~ s/^\s+|\s+$//g;
             if ( $DateField eq 'Reminder' ) {
                 if ( $IsReminder
-                    && RTx::Calendar::LocalDate( $Object->DueObj->Unix ) eq
+                    && $Object->DueObj->ISO( Time => 0, Timezone => 'user' ) eq
                     $CurrentDate )
                 {
                     $EventIcon = 'reminder.png';
@@ -274,12 +266,14 @@ CALENDAR_ICON:
                 $cf =~ s/^CF\.\{(.*)\}/$1/;
                 my $DateValue = $Object->FirstCustomFieldValue($cf);
                 next CALENDAR_ICON unless $DateValue;
-                $DateValue =~ s/(.*) (.*)/$1/;
+                my $DateObj = RT::Date->new( $Object->CurrentUser );
+                $DateObj->Set( Format => 'unknown', Value => $DateValue );
+                $DateValue = $DateObj->ISO( Time => 0, Timezone => 'user' );
                 next CALENDAR_ICON unless $DateValue eq $CurrentDate;
             } else {
                 my $DateObj = $ComparedDate . "Obj";
                 my $DateValue
-                    = RTx::Calendar::LocalDate( $Object->$DateObj->Unix );
+                    = $Object->$DateObj->ISO( Time => 0, Timezone => 'user' );
                 next CALENDAR_ICON unless $DateValue eq $CurrentDate;
             }
 

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

Summary of changes:
 html/Elements/CalendarEvent | 43 ++++++++++++++++++++++++++++---------------
 lib/RTx/Calendar.pm         | 26 ++++++++++----------------
 2 files changed, 38 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list