Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Perl program of Standard date conversion added (#5594)
Browse files Browse the repository at this point in the history
Co-authored-by: Riyazul555 <riyazulislam2003@gmail.com>
Co-authored-by: Harsh Raj <harshraj8843@gmail.com>
  • Loading branch information
3 people committed Mar 28, 2024
1 parent 5cd2981 commit 443d6db
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use strict;
use warnings;
use Time::Piece;

# Function to convert standard date format to Julian date
sub standard_to_julian {
my ($date_str) = @_;
my $date = Time::Piece->strptime($date_str, '%Y-%m-%d');
return $date->strftime('%j');
}

# Function to convert Julian date to standard date format
sub julian_to_standard {
my ($julian_date) = @_;
my $year = (localtime->year) + 1900;
my $date = Time::Piece->strptime("$year-$julian_date", '%Y-%j');
return $date->strftime('%Y-%m-%d');
}

# Test
my $standard_date = '2024-03-27';
my $julian_date = standard_to_julian($standard_date);
print "Julian date for $standard_date: $julian_date\n";

my $converted_standard_date = julian_to_standard($julian_date);
print "Standard date for $julian_date: $converted_standard_date\n";

0 comments on commit 443d6db

Please sign in to comment.