From 296d59954162845bd1da9a020a10820a142d0bce Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Thu, 28 Nov 2024 12:24:51 +0100 Subject: [PATCH] Convert dates to epoch. --- tests/os_release.pm | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/os_release.pm b/tests/os_release.pm index 13f1a519..b78a031f 100644 --- a/tests/os_release.pm +++ b/tests/os_release.pm @@ -15,11 +15,22 @@ sub strip_marks { } sub json_to_hash { + # This will convert a Json string into a valid + # Perl hash for further processing. my $json = shift; my $hash = JSON::PP->new->utf8->decode($json); return $hash; } +sub date_to_epoch { + # This takes the date in YYYY-MM-DD and converts it into + # the epoch integer. + my $dstring = shift; + my $date = Time::Piece->strptime($dstring, '%Y-%m-%d'); + my $epoch = $date->epoch; + return $epoch; +} + sub get_bodhi_eol { # This reads the Bodhi info file (downloaded in collect_web_data.pm), # parses it and returns the EOL date from that file. @@ -30,6 +41,7 @@ sub get_bodhi_eol { my $json = script_output("cat ~/version_data/bodhi-$ver.json"); my $bodhi = json_to_hash($json); my $eol = $bodhi->{"eol"}; + $eol = date_to_epoch($eol); return $eol; } @@ -57,16 +69,22 @@ sub get_schedule_eol { } sub get_current_date { - # This returns the current date in the required form - # YYYY-MM-DD which we need to see if the EOL is - # correctly set in the future. + # This returns the current date in as the epoch + # which we need to see if the EOL is correctly set in the future. my $time = localtime; - $time = $time->strftime('%Y-%m-%d'); - return $time; + my $date = $time->strftime('%Y-%m-%d'); + $date = date_to_epoch($date); + return $date; } -sub check_eol { +sub check_eol_in_year { + # This will take the EOL date from the /etc/os-release + # file and it will check that it is at least a year in + # the future (when tested on Rawhide, Branched, or Beta) + # or that it is at least a year in the future compared + # to the previously released version (when tested on a released + # version) my $eol = shift; }