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-master.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}");
4' href='#n164'>164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290