Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Nice Date (See related posts)

 sub nice_date {   
                (my $date) = @_;   
                ($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($date); 
                $month+=1; $year+=1900;   
                ($sec2, $min2, $hr2, $day2, $month2, $year2, $day_Of_Week2, $julianDate2, $dst2) = localtime();
                $month2+=1; $year2+=1900;
                if($julianDate2==$julianDate and $year==$year2) {   
                        if($hr==$hr2) {print "a few moments ago";}   
                        elsif(($hr2-$hr)==1) {print "an hour ago";}   
                        elsif(($hr2-$hr)==2) {print "two hours ago}";}   
                        elsif(($hr2-$hr)==3) {print "three hours ago";}   
                        else {print "today";}   
                }
                elsif($julianDate2==($julianDate+1) and $year==$year2) {print "yesterday";} 
                elsif(($julianDate2-$julianDate)<=2 and $year==$year2) {print "two days ago";}
                elsif(($julianDate2-$julianDate)<=5 and $year==$year2) {print "this week";}   
                else {print "$month/$day/$year";}  
        }

You need to create an account or log in to post comments to this site.


Related Posts