# Local base Lib ...

sub set_datetime_str
{
    local ($wkstr) = $_[0];
    local ($outStr) = "";
    local ($fday, $fmon, $fyea, $fhou, $fmin, $fsec, $fwday);

    # format should be: `date "+%d-%m-%Y %H:%M:%S %w"`;

    $fday=substr($wkstr,0,2); 
    $fmon=substr($wkstr,3,2); 
    $fyea=substr($wkstr,6,4); 
    $fhou=substr($wkstr,11,2); 
    $fmin=substr($wkstr,14,2); 
    $fsec=substr($wkstr,17,2); 
    $fwday=substr($wkstr,20,1); 

    # format for order criteria

    $outStr=$fyea.$fmon.$fday.$fhou.$fmin.$fsec.$wday ;
  return $outStr;
}

sub get_datetime_str
{
    local ($wkstr) = $_[0];
    local ($outStr) = "";
    local ($fday, $fmon, $fyea, $fhou, $fmin, $fsec, $fwday);

    # format should be: `date "+%d-%m-%Y %H:%M:%S $w"`;

    $fday=substr($wkstr,6,2); 
    $fmon=substr($wkstr,4,2); 
    $fyea=substr($wkstr,0,4); 
    $fhou=substr($wkstr,8,2); 
    $fmin=substr($wkstr,10,2); 
    $fsec=substr($wkstr,12,2); 
    $fsec=substr($wkstr,14,1); 

    # format for order criteria

    $outStr=$fday."-".$fmon."-".$fyea." ".$fhou.":".$fmin.":".$fsec." ".$fwday ;

  return $outStr;
}
sub set_now
{
local ($now);
if ( !$_[0] ) { 
     $now = time();
} else {
     $now=$_[0];
}     
local @tm = localtime($now);
local ($t_day, $t_mon, $t_yea, $t_hou, $t_min, $t_sec, $t_wday);

 # format should be: `date "+%d-%m-%Y %H:%M:%S $w"`;
 $t_sec=$tm[0];
 if ($t_sec < 10 ) { $t_sec="0".$t_sec;}
 $t_min=$tm[1];
 if ($t_min < 10 ) { $t_min="0".$t_min;}
 $t_hou=$tm[2];
 if ($t_hou < 10 ) { $t_hou="0".$t_hou;}
 $t_day=$tm[3];
 if ($t_day < 10 ) { $t_day="0".$t_day;}
 $t_mon=($tm[4]+1);
 if ($t_mon < 10 ) { $t_mon="0".$t_mon;}
 $t_yea=($tm[5]+1900);
 $t_wday=($tm[6]);
 $t_yead=$tm[7];
 if ($t_yead < 100 ) { $t_yead="0".$t_yead;}
 if ($t_yead < 10 ) { $t_yead="0".$t_yead;}
 $t_isdst=$tm[8];


return "$t_day-$t_mon-$t_yea $t_hou:$t_min:$t_sec $t_wday $t_yead";

}

sub show_hash
{
 local ($k,$v,$r,$lnum);
  if ( $_[1] ) { select($_[1]);}
  return if (!%{$_[0]});
  $lnum=1;
  print "_________________________________________________$lnum\n";
  while (($k,$v) = each(%{$_[0]})) { 
         $r=ref($k);
 print "HLOOO -- $r\n";
#         if ( $r eq 'HASH') { &show_hash(\%v,$_[1],$_[2]); next; };
#         if ( $r eq 'ARRAY') { &show_array(\%v,$_[1],$_[2]); next; };
#         if ( $_[1] ) { 
                print "$k$_[1]=$_[1]$v\n" ;
#         } else  { print "$k=$v\n"; }
         $lnum++;
  }
  if ( $_[1] ) { $| =1; select(STDOUT);}
}

sub show_array
{
 local ($k,$v,$r,$lnum);
  if ( $_[1] ) { select($_[1]);}
  return if (!@_[0]);
  $lnum=1;
  print "_________________________________________________$lnum\n";
  foreach $k (@_[0]) { 
         $r=ref($k->{$k});
         $v=$k->{$k};
         if ( $r eq 'HASH') { &show_hash($k->{$k},$_[1],$_[2]); next; };
         if ( $r eq 'ARRAY') { &show_array($k->{$k},$_[1],$_[2]); next; };
         if ( $_[1] ) { 
                print "$k$_[1]=$_[1]$v\n" ;
         } else  { print "$k=$v\n"; }
         $lnum++;
  }
  if ( $_[1] ) { $| =1; select(STDOUT);}
}

# To show each item from Rec in a list (hash-list: key + hash ) 
sub showrec_list
{
  return if (!%{$_[0]});
  local $lnum=1;
  local %rh,@ra;
  local ($item,$k,$v,$r);

      if ( !$_[1]  && $no_out eq 0 ) { print  "<pre>\n";};
      if ( $_[1] ) { select($_[1]);}
      while (($k,$v) = each(%{$_[0]})) { 
            if ( ! $v ) { next ;}
            $r=ref($v);
            if ( $r eq 'HASH') {
                %rh=$v;
                &show_hash(\%rh);
            } elsif ( $r  eq 'ARRAY') {
                @ra=$v;
                &show_array(\%ra);
            } else {
                print "$k\t=\t$v \n";
            }
            $lnum++;
      }
      print  "__________________________________________________\n";
      print  "TOTAL: $lnum \n";
      print  "__________________________________________________\n";
      if ( !$_[1]  && $no_out eq 0 ) { print  "</pre>\n";};
      if ( $_[1] ) { $| =1; select(STDOUT);}
}
1;  # Return true  
