Skip to content

Instantly share code, notes, and snippets.

@mshock
Created November 22, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/7602891 to your computer and use it in GitHub Desktop.
Save mshock/7602891 to your computer and use it in GitHub Desktop.
get number of seconds to sleep for once a day scheduling by hour
sub getsleep {
my ($thour) = @_;
return 0 unless $thour;
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst )
= localtime(time);
my $dif = $thour - $hour - $min / 60 - $sec / 3600;
if ( $dif >= 0 ) {
return $dif * 3600;
}
else {
return ( 24 + $dif ) * 3600;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment