about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-04-02 23:01:08 +0530
committerAndinus <andinus@nand.sh>2021-04-02 23:01:08 +0530
commit5347e2e3deab7827aa7cceb063ee9efd353eabbf (patch)
treee207a159aa74cc147616ed6cc1979d160f37d288
parentd6a67b9c2b6fdaf634d7c737a7a30c4c7446d588 (diff)
downloadara-5347e2e3deab7827aa7cceb063ee9efd353eabbf.tar.gz
Fix date parsing HEAD master
Some dates are in d/m/YYYY format, previously they used to be in
dd/mm/YYYY or maybe they were always in this format & I only noticed
it now.

I should not parse dates this way & use some module.
-rwxr-xr-xara.pl23
1 files changed, 18 insertions, 5 deletions
diff --git a/ara.pl b/ara.pl
index 5c30319..50bc4cf 100755
--- a/ara.pl
+++ b/ara.pl
@@ -253,7 +253,16 @@ foreach my $i ( 0 ... scalar @$statewise - 1 ) {
     unless ( $state_notes ) {
         my $update_info;
         my $lastupdatedtime = $statewise->[$i]{lastupdatedtime};
-        my $last_update_dmy = substr( $lastupdatedtime, 0, 10 );
+        my $last_update_dmy;
+
+        # Previously dates were in dd/mm/YYYY format, currently some
+        # are in d/m/YYYY format. This block fixes issues with
+        # d/m/YYYY format.
+        if ( substr( $lastupdatedtime, 1, 1 ) eq "/" ) {
+            $last_update_dmy = substr( $lastupdatedtime, 0, 9 );
+        } else {
+            $last_update_dmy = substr( $lastupdatedtime, 0, 10 );
+        }
 
         # Add $update_info.
         if ( $last_update_dmy
@@ -266,10 +275,14 @@ foreach my $i ( 0 ... scalar @$statewise - 1 ) {
                       eq $today->plus_days(1)->strftime( "%d/%m/%Y" ) ) {
             $update_info = "Tomorrow"; # Hopefully we don't see this.
         } else {
-            $update_info =
-                $months[substr( $lastupdatedtime, 3, 2 )] .
-                " " .
-                substr( $lastupdatedtime, 0, 2 );
+            # Previously dates were in dd/mm/YYYY format, currently
+            # some are in d/m/YYYY format. This block fixes issues
+            # with d/m/YYYY format.
+            $update_info = ( substr( $lastupdatedtime, 1, 1 ) eq "/" )
+                ? ($months[substr( $lastupdatedtime, 2, 1 )] . " "
+                   . substr( $lastupdatedtime, 0, 1 ))
+                : ($months[substr( $lastupdatedtime, 3, 2 )] . " "
+                   . substr( $lastupdatedtime, 0, 2 ));
         }
 
         my $confirmed = $fmt->format_number("$statewise->[$i]{confirmed}");