[Bps-public-commit] rt-extension-timetracking branch, master, updated. 0.09-5-gf502550

? sunnavy sunnavy at bestpractical.com
Wed Mar 14 14:07:32 EDT 2018


The branch, master has been updated
       via  f502550f1eda12e77a9b93ccd1ce0a0837d45c73 (commit)
       via  2558cd727e8aae3b4a5505f7e35df72f85b324a8 (commit)
      from  9c663cf6f3a87902aabdbee8208b2b8fdc68d17c (commit)

Summary of changes:
 html/Tools/MyWeek.html           | 11 +++++------
 lib/RT/Extension/TimeTracking.pm | 23 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit 2558cd727e8aae3b4a5505f7e35df72f85b324a8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Mar 12 21:20:03 2018 +0800

    Adjust previous/next week dates for DST
    
    In RT::Date, adding a day means adding 24*3600 seconds, which is not
    accurate when DST is involved. So a week before "2018-03-12 00:00:00"
    could become "2018-03-04 23:00:00", which is not what we want.
    
    The DST was fixed for week day iteration, but not for previous/next week
    dates until this commit.

diff --git a/html/Tools/MyWeek.html b/html/Tools/MyWeek.html
index 83e25c9..d6120bf 100644
--- a/html/Tools/MyWeek.html
+++ b/html/Tools/MyWeek.html
@@ -228,6 +228,7 @@ my ($ret, $week_start, $first_day) = RT::Extension::TimeTracking::WeekStartDate(
 my $week_end = RT::Date->new($user);
 $week_end->Set( Value => $week_start->Unix );
 $week_end->AddDays( 7 );
+RT::Extension::TimeTracking->SetDateToMidnightForDST( $week_end );
 
 my %week_worked;
 
@@ -241,10 +242,7 @@ for my $offset ( 0 .. 6 ) {
     my $date = RT::Date->new($user);
     $date->Set( Value => $week_start->Unix );
     $date->AddDays( $offset ) if $offset;
-    my $user_hour = ($date->Localtime('user'))[2];
-    if ( $user_hour == 23 ) {
-        $date->AddSeconds(3600); # to get around isuses raised by daylight saving
-    }
+    RT::Extension::TimeTracking->SetDateToMidnightForDST( $date );
 
     $week_worked{$date->ISO(Time => 0, Timezone => 'user')} = {
         date => $date,
@@ -362,6 +360,7 @@ while ( my $txn = $activity_txns->Next ) {
 my $previous_week = RT::Date->new($user);
 $previous_week->Set( Value => $week_start->Unix );
 $previous_week->AddDays( -7 );
+RT::Extension::TimeTracking->SetDateToMidnightForDST( $previous_week );
 
 </%INIT>
 
diff --git a/lib/RT/Extension/TimeTracking.pm b/lib/RT/Extension/TimeTracking.pm
index 5b93a08..f9fba36 100644
--- a/lib/RT/Extension/TimeTracking.pm
+++ b/lib/RT/Extension/TimeTracking.pm
@@ -249,6 +249,29 @@ sub WeekStartDate {
     return (1, $week_start, $first_day);
 }
 
+=head2 SetDateToMidnightForDST
+
+Accepts an RT::Date object expected to be at midnight, but probably is not yet
+because of DST, this method adjusts it accordingly. Note that the adjustment
+is inplace.
+
+=cut
+
+sub SetDateToMidnightForDST {
+    my $self = shift;
+    my $date = shift;
+    return unless $date && $date->isa( 'RT::Date' );
+
+    my $user_hour = ( $date->Localtime( 'user' ) )[ 2 ];
+    if ( $user_hour == 23 ) {
+        $date->AddSeconds( 3600 );
+    }
+    elsif ( $user_hour == 1 ) {
+        $date->AddSeconds( -3600 );
+    }
+}
+
+
 =head1 AUTHOR
 
 Best Practical Solutions, LLC E<lt>modules at bestpractical.comE<gt>

commit f502550f1eda12e77a9b93ccd1ce0a0837d45c73
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Mar 15 00:56:51 2018 +0800

    Fix "Worked Date" values for possible timezone offset in transaction search
    
    We shall consistently use "user" timezone for "Worked Date" CF,
    otherwise search values could be incorrect for users with various
    timezones.
    
    The rule of thumb is: use UTC to search datetime fields in db like
    "Created", use "user" timezone otherwise.

diff --git a/html/Tools/MyWeek.html b/html/Tools/MyWeek.html
index d6120bf..138b79d 100644
--- a/html/Tools/MyWeek.html
+++ b/html/Tools/MyWeek.html
@@ -321,8 +321,8 @@ my $cf_alias = $txns->Join(
 );
 $txns->Limit( ALIAS => $cf_alias, FIELD => 'CustomField', VALUE => $cf->id );
 $txns->Limit( ALIAS => $cf_alias, FIELD => 'ObjectType', VALUE => 'RT::Transaction' );
-$txns->Limit( ALIAS => $cf_alias, FIELD => 'Content', VALUE => $week_start->ISO(Time => 0), OPERATOR => '>=' );
-$txns->Limit( ALIAS => $cf_alias, FIELD => 'Content', VALUE => $week_end->ISO(Time => 0), OPERATOR => '<', ENTRYAGGREGATOR => 'AND', );
+$txns->Limit( ALIAS => $cf_alias, FIELD => 'Content', VALUE => $week_start->ISO(Time => 0, Timezone => 'user'), OPERATOR => '>=' );
+$txns->Limit( ALIAS => $cf_alias, FIELD => 'Content', VALUE => $week_end->ISO(Time => 0, Timezone => 'user'), OPERATOR => '<', ENTRYAGGREGATOR => 'AND', );
 
 while ( my $txn = $txns->Next ) {
     my $ticket = $txn->Object;

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


More information about the Bps-public-commit mailing list