Convert A_TickCount

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Convert A_TickCount

29 Nov 2016, 13:45

I have seen a few scripts to convert A_TickCount to a human-readable format that were somewhat useful, but not really what I wanted so I wrote these classes. I am not sure if this is the best way, but it works very well and the time since boot is accurate. If anyone has a better way to write this I would love to see it. If not I hope someone gets good use out of this.
E.g.:

Code: Select all

!o::TrayTip,Time Online, % Convert.TickCount.toDisplay(A_TickCount)

^o::
	Loop
		{
			KeyWait, o
			ToolTip, % Convert.TickCount.toDisplay(),0,0
			Sleep, 1000
			If (GetKeyState("Ctrl","P")=1)
				{
					ToolTip
					Break
				}
		}
Return
Note: - A_TickCount does not need to be passed and any tick number can be passed for evaluation, defaults to A_TickCount.
- toDisplay is great for Tooltips, Msgboxs, and TrayTips, 3 lines long: Return "Hours" A_Tab "Minutes" A_Tab "Seconds`n" h A_Tab m A_Tab s "`nSince Windows Boot."
- toFile is used for single line displays in the format 'H:M:S'
- The Convert part of the class is there because I have plans to make a whole conversion class with other things. I imagine it can be stripped and used as TickCount.toHours() etc....
- toSeconds() gives mod()ed remainder for toDisplay() and Seconds() gives the actual seconds and so on and so forth for Days, Hours, and Minutes.
Convert Tick Count Class:

Code: Select all

Class Convert {
    Class TickCount    {
	toDays(count:=False){
		Return Floor(Mod((((((count:=count?count:A_TickCount)/1000)/60)/60)/24),24))
	}
	Days(count:=False){
		Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60)/24)
	}
        toHours(count:=False){
	        Return Floor(Mod(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),60),24))
        }
	Hours(count:=False){
		Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60))
	}
        toMinutes(count:=False){
            Return Floor(Mod((((count:=count?count:A_TickCount)/1000)/60),60))
        }
        Minutes(count:=False){
            Return Floor((((count:=count?count:A_TickCount)/1000)/60))
        }
        toSeconds(count:=False){
            Return Floor(Mod(((count:=count?count:A_TickCount)/1000),60))
        }
        Seconds(count:=False){
            Return Floor(((count:=count?count:A_TickCount)/1000))
        }
	toDisplay(count:=False){
		count:=count?count:A_TickCount
		d:=Convert.TickCount.toDays(count)
		h:=Convert.TickCount.toHours(count)
		m:=Convert.TickCount.toMinutes(count)
		s:=Convert.TickCount.toSeconds(count)
		Return		"Days" A_Tab "Hours" A_Tab "Minutes" A_Tab "Seconds`n" 
				.	 d A_Tab h A_Tab m A_Tab s "`nSince Windows Boot."
	}
	toFile(count:=False){
		count:=count?count:A_TickCount
		d:=Convert.TickCount.toDays(count)
		h:=Convert.TickCount.toHours(count)
		m:=Convert.TickCount.toMinutes(count)
		s:=Convert.TickCount.toSeconds(count)		
		Return d ":" h ":" m ":" s
	}
    }
}
Any comments, fixes, or suggestions are very welcome.
Last edited by Lateralus138 on 02 Dec 2016, 19:20, edited 9 times in total.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

29 Nov 2016, 16:38

Nice script, I like the tray tip! :)
Some tips:
The mod(...) could be optional, at least, it should be omitted for hours (which now wraps around at 60), unless you consider adding days, which would be nice. If you do, the hours should be mod(...,24), not mod(...,60). As it is now, if I want to convert the tick to only seconds, I get a number from 0 to 59, that is only the correct number the first minute after boot.

substr(count,-2) gives you the millisecond part if you like. (ie, for: hour min sec ms)

Thanks for sharing.
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

29 Nov 2016, 18:45

Much appreciated for the tips!!! I realized that about Mod on the Hours and actually planned to remove it and forgot. Never even thought about having a system on for days, but I think I will implement days.
As for the 0-59; I wrote this whole thing for display time and hadn't thought about just needing total seconds. I have spent a little time on the SubStr(count,-2) and I really can't see how to do it. I was wanting to add a function for total seconds (the toSeconds mod gets the seconds left over for each minute for use in toDisplay), leaving the toSeconds for toDisplay only, but I couldn't figure out how to do it. So what I have done to get Seconds since boot time just remove the mod for to Seconds which gives total seconds (and Minutes) since boot new Function which I have added to the top post:

Code: Select all

        Seconds(count:=False){
            Return Floor(((count?count:A_TickCount)/1000))
        }
This seems to give accurate seconds since boot or provided tick count.
Again, much appreciated.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

29 Nov 2016, 20:29

Update:
Added:
toDays() ; to get days since boot
Days() ; Gets total Days since boot (not for toDisplay)
Minutes() ; Gets total minutes since boot (not for toDisplay)
Seconds() ; Gets total seconds since boot (not for toDisplay)
Hours() ; Gets total Hours since boot (not for toDisplay)

Thanks to Helgef for the advice.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

iPhilip
Posts: 814
Joined: 02 Oct 2013, 12:21

Re: Convert A_TickCount

30 Nov 2016, 02:40

Hi Lateralus138,

I believe the statements

Code: Select all

count?count:A_TickCount
in the functions toDisplay and toFile should be

Code: Select all

count := count?count:A_TickCount
Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

30 Nov 2016, 04:12

iPhilip wrote:Hi Lateralus138,

I believe the statements

Code: Select all

count?count:A_TickCount
in the functions toDisplay and toFile should be

Code: Select all

count := count?count:A_TickCount
Cheers!
Actually, It could be removed, it is handled in toSeconds, toMinutes etc anyways.
Lateralus138 wrote: I have spent a little time on the SubStr(count,-2) and I really can't see how to do it.
An example:

Code: Select all

; ^o::
; ...
ToolTip, % Convert.TickCount.toDisplay(,3),0,0
Sleep, 100 ; if useing fractions, you might want to update more often.
; ...

toFractionOfSecond(count:=False, fraction:=""){
	return Substr(count?count:A_TickCount,-2,fraction) 
}
toDisplay(count:=False,fraction:=""){
	; Valid fractions are 1,2,3
	d:=Convert.TickCount.toDays(count)
	h:=Convert.TickCount.toHours(count)
	m:=Convert.TickCount.toMinutes(count)
	s:=Convert.TickCount.toSeconds(count)
	s:= fraction ?  s "." Convert.TickCount.toFractionOfSecond(count, fraction) : s

	Return		"Days" A_Tab "Hours" A_Tab "Minutes" A_Tab "Seconds`n" 
			.	 d A_Tab h A_Tab m A_Tab s "`nSince Windows Boot."
}
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

30 Nov 2016, 07:46

I don't see why, the count? Boolean works just fine here. As I have it written it's running just fine on my machines.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

30 Nov 2016, 08:02

Lateralus138 wrote:I don't see why, the count? Boolean works just fine here. As I have it written it's running just fine on my machines.
Consider this example:

Code: Select all

count:=""
count?count:A_TickCount									; A valid expression, but no variable is assigned its value.
Msgbox, % "count is: " count							; Count is blank
msgbox, % "Expression is: " (count?count:A_TickCount)	; The value of the expression is printed
count:=count?count:A_TickCount							; Count is assigned a new value, if it is "" or 0
Msgbox, % "count is: " count							; Count is not blank
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

30 Nov 2016, 09:23

OK wow, I just tested that and, of course, you're right. And I know that, don't know I why I did that one that way, all my other countless scripts have correct booleans; made sure to douyble check lol. But I am getting accurate time with it, why so?

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

30 Nov 2016, 10:35

Pinkfloydd wrote:Nice one!

-△◄
ThanX!!!! I just fixed:

Code: Select all

count?count:A_TickCount

Code: Select all

count:=count?count:A_TickCount

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

01 Dec 2016, 04:19

Lateralus138 wrote:

Code: Select all

        Seconds(count:=False){
            Return Floor(((count:=count?count:A_TickCount)/1000))	; There is no need to assign a value to count here, it is "lost" anyways. Original version was fine
        }
	toDisplay(count:=False){
		count:=count?count:A_TickCount				; This line is not needed at all, since you do the same in the functions you call from here.
		d:=Convert.TickCount.toDays(count)
		h:=Convert.TickCount.toHours(count)
		m:=Convert.TickCount.toMinutes(count)
		s:=Convert.TickCount.toSeconds(count)
		Return		"Days" A_Tab "Hours" A_Tab "Minutes" A_Tab "Seconds`n" 
				.	 d A_Tab h A_Tab m A_Tab s "`nSince Windows Boot."
	}

But I am getting accurate time with it, why so?
You got correct result because it was handled correctly in the functions that are called by toDisplay()
Anyways, it works fine as is I think, I'm gonna put the tray tip in my misc script, since I quite often keep my pc on for many days/weeks, it is nice to check how long it has been since reboot. Thanks!
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

02 Dec 2016, 19:19

You're welcome Helgef!!!

Major change in the toHours() class for toDisplay() and toFile(): When it's been running for more than 24 hours it has to be mod()ed to reflect the day change (23:59 - 0:00) instead of keeping the hours going (24,25,26, etc...).
Change this part:

Code: Select all

toHours(count:=False){
	Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60),60))
}
to:

Code: Select all

toHours(count:=False){
	Return Floor(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),60),24))
}

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

garry
Posts: 3760
Joined: 22 Dec 2013, 12:50

Re: Convert A_TickCount

03 Dec 2016, 14:03

I tried to add an example (delta) and added milliseconds

Code: Select all

;-------- https://autohotkey.com/boards/viewtopic.php?f=6&t=25058 ---
#Warn
#Singleinstance,force

;- example 
begin1:=a_tickcount
sleep,2980
delta1:=a_tickcount - begin1

aaa:=Convert.TickCount.toFile(delta1)
bbb:=Convert.TickCount.toDisplay(delta1)
ccc:=Convert.TickCount.toDisplay(A_TickCount)
msgbox,Test=%aaa%`n%bbb%`n`nComputer is running=`n%ccc%
return

!o::TrayTip,Time Online, % Convert.TickCount.toDisplay(A_TickCount)

^o::
	Loop
		{
			KeyWait, o
			ToolTip, % Convert.TickCount.toDisplay(),0,0
			Sleep, 1000
			If (GetKeyState("Ctrl","P")=1)
				{
					ToolTip
					Break
				}
		}
Return

Class Convert {
    Class TickCount    {
	toDays(count:=False){
		Return Floor(Mod((((((count:=count?count:A_TickCount)/1000)/60)/60)/24),24))
	}
	Days(count:=False){
		Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60)/24)
	}
        toHours(count:=False){
	        Return Floor(Mod(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),60),24))
        }
	Hours(count:=False){
		Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60))
	}
        toMinutes(count:=False){
            Return Floor(Mod((((count:=count?count:A_TickCount)/1000)/60),60))
        }
        Minutes(count:=False){
            Return Floor((((count:=count?count:A_TickCount)/1000)/60))
        }
        toSeconds(count:=False){
            Return Floor(Mod(((count:=count?count:A_TickCount)/1000),60))
        }
        Seconds(count:=False){
            Return Floor(((count:=count?count:A_TickCount)/1000))
        }
        toMilliSeconds(count:=False){
            Return Floor(Mod(((count:=count?count:A_TickCount)),1000))
        }
        MilliSeconds(count:=False){
            Return Floor(((count:=count?count:A_TickCount)))
        }
	toDisplay(count:=False){
                Text1:="---------------------------------------------------------------------------"
		count:=count?count:A_TickCount
		d:=Convert.TickCount.toDays(count)
		h:=Convert.TickCount.toHours(count)
		m:=Convert.TickCount.toMinutes(count)
		s:=Convert.TickCount.toSeconds(count)
                ms:=Convert.Tickcount.toMilliSeconds(count)
		Return		"Days" A_Tab "Hours" A_Tab "Minutes" A_Tab "Seconds" A_Tab "MilliSeconds`n" . d A_Tab h A_Tab m A_Tab s A_Tab ms "`n" . Text1
	}
	toFile(count:=False){
		count:=count?count:A_TickCount
		d:=Convert.TickCount.toDays(count)
		h:=Convert.TickCount.toHours(count)
		m:=Convert.TickCount.toMinutes(count)
		s:=Convert.TickCount.toSeconds(count)
                ms:=Convert.Tickcount.toMilliSeconds(count)
		Return d "d:" h "h:" m "m:" s "s:" ms "ms"
	}
    }
}
;======================================================================
Georgie Munteer

Re: Convert A_TickCount

21 Nov 2017, 09:38

Lateralus138 wrote:You're welcome Helgef!!!

Major change in the toHours() class for toDisplay() and toFile(): When it's been running for more than 24 hours it has to be mod()ed to reflect the day change (23:59 - 0:00) instead of keeping the hours going (24,25,26, etc...).
Change this part:

Code: Select all

toHours(count:=False){
	Return Floor(((((count:=count?count:A_TickCount)/1000)/60)/60),60))
}
to:

Code: Select all

toHours(count:=False){
	Return Floor(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),60),24))
}
can you update up with the final script? hard to follow all the changes thrown around in this thread, thank you, this will be helpful
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

21 Nov 2017, 11:14

I'm fairly certain I changed all errors in the original post and the above code should reflect those changes. I actually came back here for reference the other day and I am using this on a new machine and it works just fine. I use this to log when my kids start their computers lol. the first code in the first post is an example while the second code is the actual class. I actually plan to optimize it soon, but one thing at a time... too many things to do.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

iPhilip
Posts: 814
Joined: 02 Oct 2013, 12:21

Re: Convert A_TickCount

21 Nov 2017, 21:53

Hi Lateralus138,

The tohours() function contains an error. It should be:

Code: Select all

toHours_corrected(count:=False){
  Return Floor(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),24))
}
One would not notice that there is an error until A_TickCount >= 216000000 which corresponds to 60 hours (2.5 days) of up time. To demonstrate this, consider the following comparison:

Code: Select all

MsgBox % toHours(216000000) " vs " toHours_corrected(216000000) ; Result: 0 vs 12 - 216000000 ms = 60 hours = 2 days and 12 hours

toHours(count:=False){
  Return Floor(Mod(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),60),24))
}

toHours_corrected(count:=False){
  Return Floor(Mod(((((count:=count?count:A_TickCount)/1000)/60)/60),24))
}
Below is a different implementation of your hotkeys and toDisplay() function:

Code: Select all

!o::TrayTip, Time Online, % TimeSinceBoot()

^o::
   ToggleToolTip() {
      static State := false
      if (State := !State) {
         SetTimer, Timer, 1000
         Gosub, Timer   ; Display the ToolTip right away
      } else {
         SetTimer, Timer, Off
         ToolTip
      }
      Return

      Timer:
      ToolTip, % TimeSinceBoot(), 0, 0
      Return
   }

TimeSinceBoot() {
   Seconds := A_TickCount/1000
   Minutes := Seconds/60
   Hours := Minutes/60
   Days := Hours/24
   d := Floor(Days)
   h := Floor(Mod(Hours,24))
   m := Floor(Mod(Minutes,60))
   s := Floor(Mod(Seconds,60))
   Return "Days" A_Tab "Hours" A_Tab "Minutes" A_Tab "Seconds`n" 
         . d     A_Tab  h      A_Tab  m        A_Tab  s "`n"
         . "Since Windows Boot."
}
Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

22 Nov 2017, 17:39

iPhilip wrote:Hi Lateralus138,

The tohours() function contains an error. It should be...
...
Cheers!
Thank you very much, I have been very busy as I am at the moment, but I plan to look at this and try to understand what you're showing me in a few days and I'll get the changes up soon; wish I had more time... :cry: lol

Thanks for the help and advice, I will fix soon!

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Convert A_TickCount

22 Nov 2017, 19:00

I have been using this ever since you posted it. Computer has been running 6 days 16 hours 8 minutes currently :). In my script the hour function is the same as the version suggested by iPhilip (hello :wave: ), but you do not need to assign count. Cheers, and thanks again.
User avatar
Lateralus138
Posts: 49
Joined: 30 Aug 2015, 20:52
Location: Decatur, IL.
Contact:

Re: Convert A_TickCount

22 Nov 2017, 20:12

Helgef wrote:I have been using this ever since you posted it. Computer has been running 6 days 16 hours 8 minutes currently :). In my script the hour function is the same as the version suggested by iPhilip (hello :wave: ), but you do not need to assign count. Cheers, and thanks again.
The count is so that you can pass any number to it to evaluate it, not just for the current A_TickCount. I can then log tick counts when certain actions are ran and use my converter to tell times.

K̴̡̛̻̮̼͕̬̑̋̀̂͆͛̍̑͢ȩ̮̞͍̩̯̋̈͒͌̕ę̶͓̗͖͔̹̪͗̂̈͛̓͘p̠͉̙̟̒̊͌̐͘͘͟͡͞ S̸͖̖̮̞̥͇̖̓̌͛̽̿̓̊̓̾̚͜w͇̮͓̱͇̘̯͆̓͑̋̇̉͜͝i̢͔̝̳̻̱̋̾͐̾͗͊̀̕͜͡͡n̷̡͔̦̤̝̼̩̎͌̈́̀͛̄͆̎͠ǵ̸̘̝̭̦̠̗͖͌͐͑̑̿̅̈͜͜ḯ̡̬̥̙̩̼̪̑͆̿̌́n̛̼͎̲̬͇̲͉̗̞͊̓̃̂̈͝g̸͕̜͖̪͉͔̩̓̃̀̃͌̑̋̕͘.̪̜̜̜̯̂͂̈́͛̆͗̇̍̇.̟͔͍̙̜̫̗̂̿͛͋͋̈́̾̾̿͑.̡̣̟̝̭͉̦̪́̓̀͛̑̓̐̈͘͘

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Convert A_TickCount

22 Nov 2017, 20:31

Here's an example script:
E.g. for days: you count the number of days (24-hour blocks).
E.g. for hours: you remove the days (any blocks of 24 hours), and count the number of hours.
E.g. for minutes: you remove the hours (any blocks of 60 minutes), and count the number of minutes.
E.g. for seconds: you remove the minutes (any blocks of 60 seconds), and count the number of seconds.

Code: Select all

q:: ;tick count to date and friendly format
vSec := A_TickCount//1000
vDHMS := Format("{}d {}h {}m {}s", vSec//86400, Mod(vSec,86400)//3600, Mod(vSec,3600)//60, Mod(vSec,60))
vDate := A_Now
vDate += -vSec, S
;FormatTime, vDate, % vDate, HH:mm dd/MM/yyyy
FormatTime, vDate, % vDate, ddd yyyy-MM-dd HH:mm:ss
MsgBox, % "on at: " vDate "`r`n" "on for: " vDHMS
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble, hiahkforum and 42 guests