in reply to ASCII chart that displays jobs that are running and jobs that are queued for a day

Me and my Buddy YAWPS can help.

code to get time with time offset if needed.
my $date = get_date(0);
# -------------------------------------------------------------------- +- # Get the current date and time in epoch seconds. # -------------------------------------------------------------------- +- sub get_date { my $cfg{time_offset} = shift; return time + 3600 * $cfg{time_offset}; }


formats the date to many viewing styles
my $formated_date($date, 3);
# -------------------------------------------------------------------- +- # Format date output. # -------------------------------------------------------------------- +- sub format_date { my $date = shift || &get_date; my $type = shift || 1; # Get user profile. my $query = new CGI; my %user_data = authenticate(); # Get selected date format. my $sel_date_format = (exists $user_data{date_format}) ? $user_data{date_format} : $cfg{date_format}; $sel_date_format = ($type || $type ne '') ? $type : $cfg{date_ +format}; $date = ($date || $date ne '') ? $date : get_date() +; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isds +t) = localtime($date + 3600 * $cfg{time_offset}); my ($formatted_date, $cmon, $cday, $syear); $year += 1900; $cmon = $mon + 1; $syear = sprintf("%02d", $year % 100); if ($hour < 10) { $hour = 0 . $hour; } if ($min < 10) { $min = 0 . $min; } if ($sec < 10) { $sec = 0 . $sec; } if ($cmon < 10) { $cmon = 0 . $cmon; } $cday = ($mday < 10) ? 0 . $mday : $mday; # Format: 01/15/00, 15:15:30 if (!$sel_date_format || $sel_date_format == 0) { $formatted_date = "$cmon/$cday/$syear, $hour:$min:$sec +"; } # Format: 15.01.00, 15:15:30 if ($sel_date_format == 1) { $formatted_date = "$cday.$cmon.$syear, $hour:$min:$sec +"; } # Format: 15.01.2000, 15:15:30 if ($sel_date_format == 2) { $formatted_date = "$cday.$cmon.$year, $hour:$min:$sec" +; } # Format: Jan 15th, 2000, 3:15pm if ($sel_date_format == 3) { my $ampm = 'am'; if ($hour > 11) { $ampm = 'pm'; } if ($hour > 12) { $hour = $hour - 12; } if ($hour == 0) { $hour = 12; } if ($mday > 10 && $mday < 20) { $cday = '<sup>th</sup> +'; } elsif ($mday % 10 == 1) { $cday = '<sup>st</sup>'; } elsif ($mday % 10 == 2) { $cday = '<sup>nd</sup>'; } elsif ($mday % 10 == 3) { $cday = '<sup>rd</sup>'; } else { $cday = '<sup>th</sup>'; } $formatted_date = "$months{$mon} $mday$cday, $year, $h +our:$min$ampm"; } # Format: 15. Jan 2000, 15:15 if ($sel_date_format == 4) { $formatted_date = "$wday. $months{$mon} $year, $hour:$ +min"; } # Format: 01/15/00, 3:15pm if ($sel_date_format == 5) { my $ampm = 'am'; if ($hour > 11) { $ampm = 'pm'; } if ($hour > 12) { $hour = $hour - 12; } if ($hour == 0) { $hour = 12; } $formatted_date = "$cmon/$cday/$syear, $hour:$min$ampm +"; } # Format: Sunday, 15 January, 2000 if ($sel_date_format == 6) { $formatted_date = "$week_days{$wday}, $mday $months{$m +on} $year"; } my $new_date22 = ''; my $new_mon = ''; # Format: year,month,day 20000 if ($sel_date_format == 7) { if($mday <= 9) { $new_date22 = "0$mday"; } else { $new_date22 += "$mday"; } if($mon <= 9) { $new_mon = "0$mon"; } else { $new_mon = "$mon" +; } #$cmon = $cmon - 1; $formatted_date = "$year$new_mon$new_date22"; } # Format: year,month,day 20000 if ($sel_date_format == 8) { #if(length($wday) < 2) { $wday = "0$wday"; } #$cmon = $cmon - 1; if($mon <= 9) { $new_mon = "0$mon"; } else { $new_mon += "$mon"; } $formatted_date = "$year$new_mon"; } # Format: 15/01/2000 - 03:15:30 (internal stats logfile format +). if ($sel_date_format == -1) { $formatted_date = "$cday/$cmon/$year - $hour:$min:$sec +"; } return $formatted_date; }


my $time_dif = calc_time_diff($in_date1, $in_date2, '');
This code will show the difference in hours or day
# -------------------------------------------------------------------- +- # Calculate difference between two dates. # -------------------------------------------------------------------- +- sub calc_time_diff { my ($in_date1, $in_date2, $type) = @_; my $result = $in_date1 - $in_date2; # Calculate difference in hours. if (!$type) { $result = int($result / 3600); } # Calculate difference in days. else { $result = int($result / (24 * 3600)); } return $result; }


Hope that helps! and you can Tank Yawps befor thanking me!
  • Comment on Re: ASCII chart that displays jobs that are running and jobs that are queued for a day
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: ASCII chart that displays jobs that are running and jobs that are queued for a day
by Herkum (Parson) on Oct 26, 2006 at 13:13 UTC
    The size of your format_date subroutine is too big; you should cut that down into smaller more readable blocks. You should also avoid the use of numbers as switchs to determine the output. Use CONSTANTS or Readonly variables to improve the readability.
Re^2: ASCII chart that displays jobs that are running and jobs that are queued for a day
by jdporter (Paladin) on Oct 31, 2006 at 20:57 UTC

    Horrendous. Try this:

    use Lingua::EN::Numbers::Ordinate; my @standard_formats = ( 'dd/mm/yyyy - HH:mm:ss', # -1: 15/01/2000 - 03:15:30 'MM/dd/yy, HH:mm:ss', # 0: 01/15/00, 15:15:30 'dd.MM.yy, HH:mm:ss', # 1: 15.01.00, 15:15:30 'dd.MM.yyyy, HH:mm:ss', # 2: 15.01.2000, 15:15:30 'MMM D, yyyy, h:mm tt', # 3: Jan 15th, 2000, 3:15pm 'd. MMM yyyy, hh:mm', # 4: 15. Jan 2000, 15:15 'MM/dd/yy, h:mm tt', # 5: 01/15/00, 3:15pm 'ddd, d MMMM, yyyy', # 6: Sunday, 15 January, 2000 'yyyyMMdd', # 7 'yyyyMM', # 8 ); my @months = qw( January February March April May June July August September October November December ); my @wdays = qw( Sunday Monday Tuesday Wednesday Thursday Friday Saturday ); sub d2($) { sprintf '%02d', $_[0] } sub format_date { my( $date, $date_format ) = @_; # either could be undef defined $date or $date = get_date(); defined $date_format or $date_format = get_date_format(); # from user data, cfg file $date_format++; # since they start at -1 defined $standard_formats[$date_format] or $date_format = 0; # default my( $sec, $min, $hour, $mday, $mon, $year, $wday ) = localtime $da +te; my $month = $months[$mon]; my $weekday = $wdays[$wday]; $mon++; $year += 1900; # set up the substitutions: my %v; $v{'d'} = $mday; $v{'dd'} = d2 $v{'d'}; $v{'dddd'} = $weekday; $v{'ddd'} = substr $v{'dddd'}, 0, 3; $v{'D'} = ordinate($v{'d'}); $v{'M'} = $mon; $v{'MM'} = d2 $v{'M'}; $v{'MMMM'} = $month; $v{'MMM'} = substr $v{'MMMM'}, 0, 3; $v{'y'} = $year % 100; $v{'yy'} = d2 $v{'y'}; $v{'yyyy'} = $year; $v{'H'} = $hour; $v{'HH'} = d2 $v{'H'}; $v{'h'} = $hour % 12; $v{'hh'} = d2 $v{'h'}; $v{'m'} = $min; $v{'mm'} = d2 $v{'m'}; $v{'s'} = $sec; $v{'ss'} = d2 $v{'s'}; $v{'t'} = $hour>=12?'P':'A'; $v{'tt'} = $v{'t'}.'M'; my $tf = $standard_formats[$date_format]; # do the substitutions: $tf =~ s/\b([dDMyHhmst]+)\b/ $v{$1} || $1 /ge; # this seems to be sflex's preference: $tf =~ s/ ([AP]M)/\L$1/; $tf }
    We're building the house of the future together.
Re^2: ASCII chart that displays jobs that are running and jobs that are queued for a day
by jdporter (Paladin) on Oct 27, 2006 at 12:59 UTC
    sub get_date { my $cfg{time_offset} = shift;
    syntax error at - line 4, near "$cfg{time_offset" Execution of - aborted due to compilation errors.
Re^2: ASCII chart that displays jobs that are running and jobs that are queued for a day
by SFLEX (Chaplain) on Oct 26, 2006 at 12:14 UTC
    Ahhh... I wasnt loged in when i posted the above. hehehe..