Subversion Repositories sysadmin_scripts

Rev

Rev 100 | Rev 102 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 100 Rev 101
Line 112... Line 112...
112
   return \%dataSets;
112
   return \%dataSets;
113
}
113
}
114
 
114
 
115
# will convert something like 1 day to the number of seconds (86400) for math.
115
# will convert something like 1 day to the number of seconds (86400) for math.
116
# month and year are approximations (30.5 day = a month, 365.2425 days is a year)
116
# month and year are approximations (30.5 day = a month, 365.2425 days is a year)
-
 
117
# For month and year, use the int function to convert back to integer
117
sub period2seconds {
118
sub period2seconds {
118
   my ($count, $unit) = ( shift =~ m/\s*(\d+)\s*([a-z]+)\s*/i );
119
   my ($count, $unit) = ( shift =~ m/\s*(\d+)\s*([a-z]+)\s*/i );
119
   $unit = lc $unit;
120
   $unit = lc $unit;
120
   if ( $unit eq 'hour' ) {
121
   if ( $unit eq 'hour' ) {
121
      $count *= 3600;
122
      $count *= 3600;
122
   } elsif ( $unit eq 'day' ) {
123
   } elsif ( $unit eq 'day' ) {
123
      $count *= 86400;
124
      $count *= 86400;
124
   } elsif ( $unit eq 'week' ) {
125
   } elsif ( $unit eq 'week' ) {
125
      $count *= 864000 * 7;
126
      $count *= 864000 * 7;
126
   } elsif ( $unit eq 'month' ) {
127
   } elsif ( $unit eq 'month' ) {
127
      $count *= 864000 * 30.5;
128
      $count *= int( 864000 * 30.5 );
128
   } elsif ( $unit eq 'year' ) {
129
   } elsif ( $unit eq 'year' ) {
129
      $count *= 86400 * 365.2425;
130
      $count *= int( 86400 * 365.2425 );
130
   } else {
131
   } else {
131
      die "Unknown units [$unit] in period2seconds\n";
132
      die "Unknown units [$unit] in period2seconds\n";
132
   }
133
   }
133
   return $count;
134
   return $count;
134
}
135
}