Jump to content

_checktimeblock() Udf


Onoitsu2
 Share

Recommended Posts

This is something I just thought of and since I did not have a computer in front of me I whipped out my programming notepad, and took like 6 pages (drafts) front and back to get the formatting correct, and correct order of the If statements, and the proper logic.

I seem to do this often, I will write entire pages of code without ever having a computer to test them on, and they run great :think:

I guess I am just touched in that way.

*Waits for someone one to smirk and say "Ya touched in the head"* *Agree*

Also there is a function _FormatTimeBlock() which, well, formats a timeblock.

A timeblock is defined as "hh:mm-hh:mm" and is in 24hr format (military time)

Example: $timeblock = "00:30-13:30" <==== is 12:30am - 1:30pm

As always PLEASE PLEASE PLEASE post any comments, complaints, rants, flames, props, etc. that anyone may have...

Ok nuff said here it is...

_CheckTimeBlock.au3

#include-once
; ----------------------------------------------------------------------------
;
; AutoIt Version: v3.1.1.121 (beta) used to make
; Author:        Onoitsu2 <Onoitsu2@yahoo.com>
;
; Script Function: _CheckTimeBlock()
;   Checks if your system time is within a timeblock and returns
;   0 if it IS in the range, or 1 if it is NOT.
;
;   Nifty Feature=============> A range can be from say, 10:00-08:59
;                               you can have a range include the mid-night
;                               THIS IS THE REASON FOR THE LARGE CODE...
;                               Took 6 written pages (drafts) to get code correct
;                               had to do on paper as was not at computer
;                               when I had the idea.
;
;   Works with times in following formats (ALL Military):
;       USE:    TRANSLATES TO:
;       00:30 = 12:30AM
;       13:30 = 1:30PM
;       etc.  = etc.
;
;   Example Call: _CheckTimeBlock(00,30,01,30)
;
; ----------------------------------------------------------------------------

Func _CheckTimeBlock($tsh=0,$tsm=0,$teh=0,$tem=0)
    
If NOT ($tsh = 0 AND $tsm = 0 AND $teh = 0 AND $tem = 0) Then
    IF NOT ($tsh = $teh AND $tsm = $tem) Then
        $times_starth = $tsh
        $times_startm = $tsm
        $times_endh = $teh
        $times_endm = $tem
    Else
        SetError(1); Start and End Times are Equal!!
        Return 0; Since timeblock is a full 24hour period any time really is IN this timeblock
    EndIf
Else
    If ($times_starth = $times_endh AND $times_startm = $times_endm) Then
        SetError(1); Start and End Times are Equal!!
        Return 0; Since timeblock is a full 24hour period any time really is IN this timeblock
    EndIf
    If $times_endh < $times_starth Then
        If @HOUR = 0 Then
            If @HOUR < $times_endh Then
                Return 0
            ElseIf @HOUR = $times_endh Then
                If @MIN >= $times_endm Then
                    Return 1
                Else
                    Return 0
                EndIf
            EndIf
        ElseIf @HOUR <= 23 Then
            If @HOUR < $times_starth Then
                If @HOUR < $times_endh Then
                    Return 0
                ElseIf @HOUR = $times_endh Then
                    If @MIN >= $times_endm Then
                        Return 1
                    Else
                        Return 0
                    EndIf
                EndIf
                Return 1
            ElseIf @HOUR = $times_starth Then
                If @MIN >= $times_startm Then
                    Return 0
                Else
                    Return 1
                EndIf
            ElseIf @HOUR > $times_starth Then
                If @HOUR < $times_endh Then
                    Return 0
                Else
                    Return 1
                EndIf
            EndIf
        EndIf
    ElseIf $times_endh > $times_starth Then
        If @HOUR > $times_starth Then
            If @HOUR < $times_endh Then
                Return 0
            ElseIf @HOUR = $times_endh Then
                If @MIN >= $times_endm Then
                    Return 1
                Else
                    Return 0
                EndIf
            ElseIf @HOUR > $times_endh Then
                Return 1
            EndIf
        ElseIf @HOUR = $times_starth Then
            If @MIN >= $times_startm Then
                Return 0
            Else
                Return 1
            EndIf
        ElseIf @HOUR < $times_starth Then
            Return 1
        EndIf
    ElseIf $times_endh = $times_starth Then
        If @MIN >= $times_endm Then
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndIf
EndFunc

; ----------------------------------------------------------------------------
;
; AutoIt Version: v3.1.1.121 (beta) used to make
; Author:        Onoitsu2 <Onoitsu2@yahoo.com>
;
; Script Function: _FormatTimeBlock()
;   Formats a given timeblock for use with the _CheckTimeBlock() function.
;   This makes it so a parameter is not required by the _CheckTimeBlock()
;   function, so it makes using in an Adlib easier. To change the time of
;   the Adlib'd _CheckTimeBlock() make a call to this function with a
;   timeblock variable, or string in the format: "00:00-00:00"
;
;   Example Call: _FormatTimeBlock($timeblock)
;                 _FormatTimeBlock("00:30-13:30")
;
; ----------------------------------------------------------------------------

Func _FormatTimeBlock($times)
If StringInStr($times,"-") Then
    $dashpos = StringInStr($times,"-")
    $times_start = StringMid($times,1,$dashpos-1)
    Global $times_starth = StringLeft($times_start,2)
    Global $times_startm = StringRight($times_start,2)
    $times_end = StringMid($times,$dashpos+1,StringLen($times))
    Global $times_endh = StringLeft($times_end,2)
    Global $times_endm = StringRight($times_end,2)
Else
    Global $times_starth = StringLeft($times,2)
    Global $times_startm = StringRight($times,2)
    Global $times_endh = StringLeft($times,2) + 1
    Global $times_endm = StringRight($times,2) + 1
EndIf
EndFunc

Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font]

Link to comment
Share on other sites

i don't see any real use for this. At least you learnt something from it.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

i don't see any real use for this. At least you learnt something from it.

The reason I made this is so that I can easily check if a person is logged on outside of a certain time, and then if they are log them out, or I can make it close an app, or whatever ...

Or you can do the opposite, and block during this certain times just by using a NOT on the returned value.

I find this is a good item for using if you have kids, as you can dictate mandated logon and logoff times using it.

#include "_CheckTimeBlock.au3"
#notrayicon
Global $timeblock
$timeblock = "15:30-23:30"
_FormatTimeBlock($timeblock)
While 1
    $chk = _CheckTimeBlock()
If $chk Then
MsgBox(0,"","Logged On Outside of Scheduled Hours..."&@CRLF&_Iif($times_starth > 12,$times_starth-12,$times_starth)&":"&$times_startm&_Iif($times_starth < 12," AM"," PM")&"-"&_Iif($times_endh > 12,$times_endh-12,$times_endh)&":"&$times_endm&_Iif($times_endh < 12," AM"," PM")&@CRLF&"Logging off NOW!!!")
Shutdown(4)
Else
    EndIf
Sleep(10000)
WEnd

This would check if your kid is on the computer before 3:30pm and after 11:30pm

Laterzzz,

Onoitsu2

Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font]

Link to comment
Share on other sites

*Bump*

65 Views and only 1 post other than the one by myself...

Is no one interested in checking if system time is within a time range, and doing it easily??

I guess not...

Can I at least get some comments, or ideas for improving this...?

Laterzzz,

Onoitsu2

Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font]

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 years later...

I'm reviving this ancient thread because it gave me exactly what I needed for my project (and because there was some question as to whether this code would ever be useful).

I'm writing a script to circumvent the rule in my company's group policy that locks my screen after 10 minutes of idle time, causing me to have to re-enter my password. I want it to keep me alive during business hours, but then let the computer go into screen saver mode after business hours so that my monitor isn't on all night.

Here is my script. This ensures that your computer is never idle for more than 8 minutes during the specified time block. I'm new at this so feel free to critique and offer any feedback to improve it:

; keepalive.au3
#Include <Date.au3>
#Include <Timers.au3>
#Include <Misc.au3>
#Include "_CheckTimeBlock.au3"

; Make sure only one instance is running
if _Singleton("keepalive",1) = 0 Then
    Msgbox(0,"Warning","keepalive is already running")
    Exit
EndIf

; Code for tray
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode",1)
TraySetClick(16)
$infoitem = TrayCreateItem("Info")
TrayItemSetOnEvent(-1,"ShowInfo")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")
TraySetState()

; Functions for tray menu items
Func ShowInfo()
    Msgbox(0,"Info","Prevents computer from idling during specified hours.")
EndFunc
Func ExitScript()
    Exit
EndFunc

; Specify start and end times
Global $timeblock
$timeblock = "7:45-17:30"
_FormatTimeBlock($timeblock)

While 1
    $chk = _CheckTimeBlock()
    If $chk=0 Then ; if we are within the timeblock, $chk will return 0.
        $idle = _Timer_GetIdleTime() ; check current idle time
        If $idle >= 240000 Then ; if idle time is greater than 4 minutes (1 second = 1000)
            $m = MouseGetPos() ; wiggle mouse
            MouseMove($m[0], $m[1]+2)
            MouseMove($m[0], $m[1])
        EndIf
    EndIf
    Sleep(240000) ; wait 4 minutes to check again
WEnd

keepalive.au3

Edited by sizzam
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...