raghvens has asked for the wisdom of the Perl Monks concerning the following question:
Dear Perl Monks,
I am trying to write a script to get the date difference between the clearcase view created with the current date. I know that there is a module readily available in perl to get datediff but without using it, I want to write the script which will tell the view created in Years, Months and days. Please suggest.
@date = localtime(); $y = sprintf("%d %02d %02d\n",$date[5]+1900,$date[4]+1,$date[3]); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); $year += 1900; @MonthNames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec"); chomp($y); #print "\nToday's Date ----> $y"; #--------------------------------------------------------------------- +--------- # Timestamp / get actual date, check for environment, configuration fi +les #--------------------------------------------------------------------- +--------- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year += 1900; @date = localtime(); $year = sprintf("%s-%02d-%02d\n",$date[5]+1900,$date[4]+1,$date[3]); chomp($year); open(LOG, ">~veiwreport.txt") or die $!; #@vlist = "raghvens_test_view"; @vlist = `cleartool lsview -s`; foreach (@vlist) { chomp($_); #system "color 0A"; print "\nTag: $_"; print LOG "\nTag: $_"; @view_space = `cleartool space -view $_`; foreach $line (@view_space) { if ($line =~ m/is\s(.*)\sMb/) { #chomp($1); #$size=$1; #print " View-Size:$size Mb"; @size = split(/\s/,$line); #chomp($size[1]); print " Size : $size[7] Mb"; print LOG " Size : $size[7] Mb"; } } @view_details = `cleartool lsview -prop -full $_`; foreach $vd (@view_details) { if($vd =~ m/Last accessed/) { @arr = split(/\s+/,$vd); $accdate = $arr[2]; @acc = split(/T/,$accdate); chomp(@acc[0]); print "\tLast accessed : @acc[0]"; print LOG "\t Last accessed : @acc[0]"; } if ($vd =~ /Created/) { @a=split(".",$vd,1); #print "\nHellooooooo----> $a[0]"; @b=split("T",$a[0]); #@c=split("\w",$b[0]); $b[0] =~ s/(\w)*/ /; $b[0] =~ s/\s+//; print " created on $b[0]"; print LOG " created on $b[0]"; @c=split(/\-/,$b[0]); $d=@c[0]." ".@c[1]." ".@c[2]; #print "\nDate :: @c[2]"; #print "\nMonth:: @c[1]"; #print "\nYear :: @c[0]"; @ar=split("-",$d); $i=0; $i=sprintf("%2d",$i); foreach $month(@MonthNames) { $i++; if ($month eq $ar[1]) { $month=$i; if ($i <= 9) { $month= "0".$i; } $datee=$ar[2].$month.$ar[0]; #print "\nNEW DATE ::$datee \n"; } } #print "\n NEW DATE :: $datee \n"; $datee=$ar[2].$month.$ar[0]; #print"\n>>>>>>>>>>>>>>>$datee<<<<<<<<"; } } # print " >>>>>>>>>>>>> $d \n"; $d= sprintf("%s %02d %02d\n",$date[5]+1900,$date[4]+1,$date[3]); #print " \nView created on ----> $d \n"; @curt = $y; @crt = $b[0]; foreach(@curt) { @ncurt = (split/\s/,$_); foreach $nc (@ncurt) { # print "\n$nc"; } } foreach(@crt) { @ncrt = (split/\-/,$_); foreach $ncr (@ncrt) { #print "\n$ncr"; } } for($i=0;$i<=$#ncurt;$i++) { for($j=0;$j<=$#ncrt;$j++) { #print "\nValue of i is $i and j is $j"; $diffyr = $ncurt[0] - $ncrt[0]; #print "\nValue of i is $crt[1] and j is $curt[1]"; #print "\nYear difference is $diffyr \n"; $diffmon = $ncurt[1] - $ncrt[1]; if($diffmon < 0) { $diffmon =~ s/-//;} #print "\nMonth difference is $diffmon \n"; $diffdat = $ncurt[2] - $ncrt[2]; if($diffdat < 0) { $diffdat =~ s/-//;} #print "\nDate difference is $diffdat \n"; } } $diff = $diffyr." Yrs"." ".$diffmon." Months"." ".$diffdat." Days" +; # print "\nDifference between the dates: $diff \n"; print "\nAge: is $diff old \n"; print LOG "\nAge: is $diff old \n"; } close (LOG);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date difference
by Anonymous Monk on Oct 06, 2009 at 15:19 UTC | |
by raghvens (Novice) on Oct 08, 2009 at 09:36 UTC | |
by raghvens (Novice) on Oct 09, 2009 at 10:49 UTC | |
by afoken (Chancellor) on Oct 10, 2009 at 06:33 UTC | |
|
Re: date difference
by mickep76 (Beadle) on Oct 09, 2009 at 11:34 UTC |