From 60e9db79a3940d8d719d8028d204d5389c131f19 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 6 Jun 2020 14:48:17 +0530 Subject: Use Time::Moment for $file_mtime instead of DateTime First step to replacing DateTime with Time::Moment, DateTime is very huge, no need to load that large module for simple tasks, it'll also make the program run faster. This comparison happens in utc time instead of converting it to other time zone which was meaningless anyways. --- ara.pl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'ara.pl') diff --git a/ara.pl b/ara.pl index fec9c3d..b3bbff9 100755 --- a/ara.pl +++ b/ara.pl @@ -6,6 +6,7 @@ use feature 'say'; use DateTime qw( ); use Path::Tiny; +use Time::Moment; use JSON::MaybeXS qw( decode_json ); use Text::Table::Tiny qw( generate_table ); use Text::ASCIITable; @@ -40,17 +41,14 @@ my $file_mtime; # If $file exists then get mtime. if ( -e $file ) { my $file_stat = path($file)->stat; - $file_mtime = DateTime->from_epoch( - epoch => $file_stat->[9], - time_zone => 'Asia/Kolkata', - ); + $file_mtime = Time::Moment->from_epoch( $file_stat->[9] ); } # Fetch latest data only if the local data is older than 8 minutes or # if the file doesn't exist. if ( ( not -e $file ) or ( $file_mtime < - DateTime->now( time_zone => 'Asia/Kolkata' )->subtract( minutes => 8 ) ) ) { + Time::Moment->now_utc->minus_minutes(8) ) ) { require File::Fetch; # Fetch latest data from api. -- cgit 1.4.1-2-gfad0