#!/usr/bin/env perl use strict; use warnings; use Date::Manip; use Lingua::EN::Numbers::Ordinate; my $date = Date::Manip::Date->new(); $date->parse('2019-07-31'); my $month = $date->printf('%m'); $month =~ s/^0+//g; my $dayofyear = $date->printf('%j'); $dayofyear =~ s/^0+//g; my $dayofmonth = $date->printf('%d'); $dayofmonth =~ s/^0+//g; my $year = $date->printf('%Y'); # December starts on 1st of September... my $septstart = Date::Manip::Date->new(); $septstart->parse($year . '-09-01'); my $septday = $septstart->printf('%j'); $septday =~ s/^0+//g; my $outstring = ''; if($month == 8) { # August $outstring = ordinate($dayofmonth) . ' August ' . $year; } else { # December if($month > 8) { my $daycount = $dayofyear - $septday + 1; $outstring = ordinate($daycount) . ' December ' . $year } else { # Uh-oh, this is the continuation of last years december... my $decend = Date::Manip::Date->new(); $decend->parse($year . '-12-31'); my $decday = $decend->printf('%j'); $decday =~ s/^0+//g; my $prevyeardays = $decday - $septday + 1; my $daycount = $dayofyear + $prevyeardays; $year--; # previous years december $outstring = ordinate($daycount) . ' December ' . $year } } print $outstring, "\n"; #### #!/usr/bin/env perl use strict; use warnings; use Date::Manip; use Lingua::EN::Numbers::Ordinate; my $date = Date::Manip::Date->new(); $date->parse('2019-07-31'); #### my $month = $date->printf('%m'); $month =~ s/^0+//g; my $dayofyear = $date->printf('%j'); $dayofyear =~ s/^0+//g; my $dayofmonth = $date->printf('%d'); $dayofmonth =~ s/^0+//g; my $year = $date->printf('%Y'); #### # December starts on 1st of September... my $septstart = Date::Manip::Date->new(); $septstart->parse($year . '-09-01'); my $septday = $septstart->printf('%j'); $septday =~ s/^0+//g; #### my $outstring = ''; if($month == 8) { # August $outstring = ordinate($dayofmonth) . ' August ' . $year; #### } else { # December if($month > 8) { my $daycount = $dayofyear - $septday + 1; $outstring = ordinate($daycount) . ' December ' . $year #### } else { # Uh-oh, this is the continuation of last years december... my $decend = Date::Manip::Date->new(); $decend->parse($year . '-12-31'); my $decday = $decend->printf('%j'); $decday =~ s/^0+//g; my $prevyeardays = $decday - $septday + 1; my $daycount = $dayofyear + $prevyeardays; $year--; # previous years december $outstring = ordinate($daycount) . ' December ' . $year } } #### print $outstring, "\n";