From 5347e2e3deab7827aa7cceb063ee9efd353eabbf Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 2 Apr 2021 23:01:08 +0530 Subject: Fix date parsing 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. --- ara.pl | 23 ++++++++++++++++++----- 1 file 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}"); -- cgit 1.4.1-2-gfad0