]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Bug 19 fix.
authorWill Budic <redacted>
Wed, 19 Feb 2020 21:23:03 +0000 (08:23 +1100)
committerWill Budic <redacted>
Wed, 19 Feb 2020 21:23:03 +0000 (08:23 +1100)
Current Development Check List.md
htdocs/cgi-bin/data.cgi

index 9f3feb153ff7c94d99d91ee6ebfb76f9aa2ea685..cb9a762e27c6c0f3e955dbce4e2951c6281e2e88 100644 (file)
@@ -79,7 +79,7 @@ This version is not compatible in data structure to prior versions. Data migrati
 
 ### v. 1.8 Encountered/Fixed
 
-* Bug 19 - Same day datediff is displaying wrong report in time stack on the page.
+* &#10004; Bug 19 - Same day datediff is displaying wrong report in time stack on the page.
 * &#10004; Issue 18 - Setting excludes for views, deliveres page but long delays with server finished exchange (page doesn't hang).
   * The page is server delivered, if sections contain external internet links, this timeouts page browser delivery if the internet is down.
 * &#10004; Bug 17 - Editing of entries on occasions, duplicates entries.
index cd83e1f5070293355168c25e86919418cbcc361a..56b93a0105cd0f86611d0d024cdffdede24bca4b 100755 (executable)
@@ -6,13 +6,14 @@
 
 use strict;
 use warnings;
-use Try::Tiny;
 use Switch;
 
 
 use CGI;
 use CGI::Session '-ip_match';
 use DBI;
+use Exception::Class ('LifeLogException');
+use Syntax::Keyword::Try;
 
 use DateTime qw();
 use DateTime::Format::SQLite;
@@ -37,14 +38,14 @@ if(!$userid||!$dbname){
 
 my $database = Settings::logPath().$dbname;
 my $dsn= "DBI:SQLite:dbname=$database";
-my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die "<p>Error->"& $DBI::errstri &"</p>";
+my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 })  or LifeLogException->throw($DBI::errstri);
 
 #Fetch settings
 my $imgw = 210;
 my $imgh = 120;
 Settings::getConfiguration($db);
 Settings::getTheme();
-
+my $human = DateTime::Format::Human::Duration->new();
 
 
 ### Page specific settings Here
@@ -104,18 +105,21 @@ sub DisplayDateDiffs{
             $stm = $stm." OR ";
         }
     }
-    $stm .= ';';
+    $stm .= ' ORDER BY PID;';
     print $cgi->pre("###[stm:$stm]") if($DEBUG);
     $st = $db->prepare( $stm );
-    $st->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
+    $st->execute();
 
     my ($dt,$dif,$first,$last,$tnext, $dt_prev) = (0,0,0,0,0,$today);
     while(my @row = $st->fetchrow_array()) {
-
-         $dt = DateTime::Format::SQLite->parse_datetime( $row[0] );
+         my $rdat = $row[0];
+         my $rlog = $row[1];
+         $rlog =~ m/\n/;
+         $dt  = DateTime::Format::SQLite->parse_julianday( $rdat );
+         $dt->set_time_zone(&Settings::timezone);
          $dif = dateDiff($dt_prev, $dt);
          $tbl .= '<tr class="r1"><td>'. $dt->ymd . '</td>
-                    </td><td style="text-align:left;">'.$row[1]."</td></tr>".
+                    </td><td style="text-align:left;">'.$rlog."</td></tr>".
                  '<tr class="r0"><td colspan="2">'.$dif.'</td> </tr>';
          $last = $dt_prev;
          $dt_prev = $dt;
@@ -136,18 +140,23 @@ print '<center><div>'.$tbl.'</div><br><div><a href="main.cgi">Back to Main Log</
 
 
 sub dateDiff {
-    my($d1,$d2,$ff)=@_;
-    my $span = DateTime::Format::Human::Duration->new();
-    my $dur = $span->format_duration($d2 - $d1);
-    my $t = "<font color='red'> today </font>";
-       $t = "" if ($d1!=$today);
-return sprintf( "%s <br>between $t $ff %s and %s", $dur, boldDate($d1), boldDate($d2));
+    my($d1,$d2,$ff,$sw)=@_;
+    if($d1->epoch()>$d2->epoch()){
+        $sw = $d1;
+        $d1 = $d2;
+        $d2 = $sw;
+    }else{$sw="";}
+    my $dur = $human->format_duration_between($d1, $d2);
+    my ($t1,$t2) = ("","");
+    $t1 = "<font color='red'> today </font>" if ($d1->ymd() eq $today->ymd());# Notice in perl == can't be used here!
+    $t2 = "<font color='red'> today </font>" if ($d2->ymd() eq $today->ymd());
+return sprintf( "%s <br>between $ff $t1 %s and $t2 %s[%s]", $dur, boldDate($d1), boldDate($d2), $d1->ymd());
 
 }
 
 sub boldDate {
     my($d)=@_;
-return "<b>".$d->ymd."</b> ".$d->hms;
+return "<b>".$d->ymd()."</b> ".$d->hms;
 }