- Timestamp:
- 1999-07-16T11:19:12+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/sorttools.pm
r383 r392 16 16 $$stringref =~ s/^\s+//; 17 17 } 18 19 18 20 19 # format an english name for sorting … … 36 35 } 37 36 37 # takes arguments of day, month, year and converts to 38 # date of form yyyymmdd. month may be full (e.g. "January") 39 # or abbreviated (e.g. "Jan"). Years like "86" will be 40 # assumed to be "1986". 41 sub format_date { 42 my ($day, $month, $year) = @_; 43 44 my %months = ('january' => '01', 'jan' => '01', 'february' => '02', 'feb' => '02', 45 'march' => '03', 'mar' => '03', 'april' => '04', 'apr' => '04', 46 'may' => '05', 'june' => '06', 'jun' => '06', 'july' => '07', 47 'jul' => '07', 'august' => '08', 'aug' => '08', 'september' => '09', 48 'sep' => '09', 'october' => '10', 'oct' => '10', 'november' => '11', 49 'nov' => '11', 'december' => '12', 'dec' => '12'); 50 51 $month =~ tr/A-Z/a-z/; 52 53 if ($day < 1) { 54 print STDERR "sorttools::format_date WARNING day $day out of range\n"; 55 $day = "01"; 56 } elsif ($day > 31) { 57 print STDERR "sorttools::format_date WARNING day $day out of range\n"; 58 $day = "31"; 59 } 60 61 $day = "0$day" if (length($day) == 1); 62 63 if (!defined $months{$month}) { 64 print STDERR "sorttools::format_date WARNING month $month out of range\n"; 65 $month = "01"; 66 } else { 67 $month = $months{$month}; 68 } 69 70 if ($year !~ /^\d\d\d\d$/) { 71 if ($year !~ /^\d\d$/) { 72 print STDERR "sorttools::format_date WARNING year $year assumed to be 19$year\n"; 73 $year = "19" . $year; 74 } else { 75 print STDERR "sorttools::format_date WARNING year $year out of range - reset to 1900\n"; 76 $year = "1900"; 77 } 78 } 79 80 return "$year$month$day"; 81 } 82 83 38 84 1;
Note:
See TracChangeset
for help on using the changeset viewer.