3.141.31.209 |    

Navigation

Google Advertisement

This function checks if we are currently in working hours.
if is_workingtime ; then
    # do something ;)
fi


is_workingtime
  1. # *******************************************************
  2. # This function checks if we are currently in working hours.
  3. # The weekend and from 18:00 to 06:00 is not working time.
  4. #
  5. # @return bool
  6. #
  7. function is_workingtime () {
  8.  
  9. # Get the day of week as number
  10. local dow=$(date +%u)
  11.  
  12. # Get the hour and minutes without : character
  13. local nwh=$(date +%H%M)
  14.  
  15. # Check, if we have weekend (6=Saturday, 7=Sunday)
  16. if [ $dow -eq 6 -o $dow -eq 7 ]; then
  17.     return 1
  18. else
  19.     # Check if we are outsite the working hour (18:00 - 06:00)
  20.     if [ $nwh -ge 1800 -o $nwh -le 0600 ]; then
  21.         return 1
  22.     else
  23.         # Okay, we have working time ;)
  24.         return 0
  25.     fi
  26. fi
  27.  
  28. }
Parsed in 0.002 seconds at 413.71 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 1 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)