Display time right justified in progress window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bill
Posts: 33
Joined: 09 Sep 2017, 12:58

Display time right justified in progress window

21 Sep 2017, 20:57

Text in a progress window can be centered, by default, or left justified but there is no option to right justify. I display the expiry time of an event in a progress window in 12 hour format:

9:20 pm
10:20 pm

In order to right justify I've resorted to hh:mm tt

09:20 pm
10:20 pm

but this is ugly.

If I use two spaces, %A_Space%%A_Space%, they line up correctly:

  9:20 pm
10:00 pm

but I can't figure out the expression to replace the "0" with "%A_Space%%A_Space%" for the relevant times.

Can someone help?

Thank you,
Bill
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Display time right justified in progress window

21 Sep 2017, 21:43

I assume you are trying to replace times leading with 0 with 2 spaces?
Use SubStr to check the first digit and replace it
or
use RegExReplace to do it all at once
:cookie:

Code: Select all

old_time := "09:20 pm"
new_time := RegExReplace(old_time, "^0(\d\:\d\d\s*[apAP][mM])$", "  $1")
MsgBox, % new_time
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Bill
Posts: 33
Joined: 09 Sep 2017, 12:58

Re: Display time right justified in progress window

21 Sep 2017, 23:11

Thank you for the tip.

Assuming YYYYMMDDHHMMSS and a variable named "Expires", this seems to work:

if SubStr(Expires,9,1)=0
FormatTime, Expires, %Expires%, %A_Space%%A_Space%h:mm tt
Else
FormatTime, Expires, %Expires%, h:mm tt

but only within am or pm.

For example, if the time is 1:00 am and I set the event to expire any time up to 9:59 am, it inserts the two spaces and displays correctly:

  9:59 am

But if the time is am and I set the event to expire in pm, it ignores the spaces:

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

Re: Display time right justified in progress window

22 Sep 2017, 05:48

The issue is 24-hour v. 12-hour formats. These numbers are 2-digits long in 12-hour format: 10|11|12|22|23|00 (i.e. 10/11/12).

Code: Select all

q::
vDate := A_Now
vOutput := ""
Loop, 24
{
	vHour := SubStr(vDate, 9, 2)
	vPfx := RegExMatch(vHour, "10|11|12|22|23|00") ? "" : A_Space A_Space
	FormatTime, vTime, % vDate, h:mm tt
	vOutput .= vDate " " vPfx vTime "`r`n"
	vDate += 1, Hours
}
MsgBox, % Clipboard := vOutput
return
You can right align text in a Progress window like this:

Code: Select all

q::
DetectHiddenWindows, On
Progress, zh0 b1 c0 fs18, % "hello world"
Control, Style, +0x2, Static1, ahk_class AutoHotkey2 ;SS_RIGHT := 0x2
Sleep 2000
Progress, Off
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Bill
Posts: 33
Joined: 09 Sep 2017, 12:58

Re: Display time right justified in progress window

22 Sep 2017, 14:07

Thank you for the example code which I will try to get my head around. Your second suggestion would be ideal but at the moment I'm staying with the original AutoHotKey. Very inelegant, but specifying each hour works:

If SubStr(Expires,9,2)=01
FormatTime, Expires, %Expires%, %A_Space%%A_Space%h:mm tt
Else If SubStr(Expires,9,2)=02
FormatTime, Expires, %Expires%, %A_Space%%A_Space%h:mm tt
...
Else If SubStr(Expires,9,2)=10
FormatTime, Expires, %Expires%, h:mm tt
Else If SubStr(Expires,9,2)=11
FormatTime, Expires, %Expires%, h:mm tt
Else If SubStr(Expires,9,2)=12
FormatTime, Expires, %Expires%, h:mm tt
Else If SubStr(Expires,9,2)=13
FormatTime, Expires, %Expires%, %A_Space%%A_Space%h:mm tt
...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Display time right justified in progress window

22 Sep 2017, 14:25

I think that this will do what you want:

Code: Select all

vPfx := RegExMatch(SubStr(Expires,9,2), "10|11|12|22|23|00") ? "" : A_Space A_Space
FormatTime, Expires, % Expires, % vPfx "h:mm tt"
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Bill
Posts: 33
Joined: 09 Sep 2017, 12:58

Re: Display time right justified in progress window

22 Sep 2017, 18:23

That works perfectly. Thank you.

In my progress window I show the time, using font size 46, with a smaller 2nd progress window centered over the am/pm showing a countdown in h:mm:ss, using font size 18. This solution moves the time and keeps the second progress window in a fixed position. One other aim is to allow the time to center in the progress window and move the second progress window as necessary to center over am/pm. It needs to know just 2 positions - one for hours 1 am/pm - 9 am/pm, and a second position for hours 10 am/pm - 12 am/pm. Using my previous inelegant code, I tried:

If SubStr(Expires,9,2)=02
Progress, 2: x1500 ...
Else If SubStr(Expires,9,2)=10
Progress, 2: x1540 ...
etc.

but this doesn't work. Can you suggest a solution?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Display time right justified in progress window

22 Sep 2017, 19:08

Could you please provide your code in full, or in a fuller form, for a better answer.

[EDIT:] Using a similar approach to the previous code, this might be all you need:

Code: Select all

vWinX := RegExMatch(SubStr(Expires,9,2), "10|11|12|22|23|00") ? 1540 : 1500
Progress, % "2: x" vWinX, % "hello world"
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Bill
Posts: 33
Joined: 09 Sep 2017, 12:58

Re: Display time right justified in progress window

22 Sep 2017, 21:10

On my monitor the countdown centers over the pm. The full code allows me to select the time.

Code: Select all

11pm:
targettime = 2300
Gui, +AlwaysOnTop +OwnDialogs +ToolWindow
target = %A_YYYY%%A_MM%%A_DD%%targettime%00
EnvSub, target, %A_Now%, Seconds

Hours := target // 3600
MinutesLeft := target - (Hours * 3600)
Minutes := MinutesLeft // 60
Seconds := MinutesLeft - (Minutes * 60)
SleepTime := target * 1000
If (SleepTime > 0)
Goto, CountdownSleep
Sleep, %SleepTime%
Return

CountdownSleep:
EnvAdd, Expires, %Target%, seconds
FormatTime, Expires, %Expires%, h:mm tt

StartHour = %Hours%
StartMinutes = %Minutes%
StartSeconds = %Seconds%

Aim = %A_Now%
Aim += %StartHour%, Hours
Aim += %StartMinutes%, Minutes
Aim += %StartSeconds%, Seconds

DiffHour = %Aim%
DiffHour -= A_Now, Hours
DiffMinutes = %Aim%
DiffMinutes -= A_Now, Minutes
DiffMinutes := DiffMinutes - 60 * DiffHour
DiffSeconds = %Aim%
DiffSeconds -= A_Now, Seconds
DiffSeconds := DiffSeconds - 60 * ( DiffMinutes + 60 * DiffHour )

If (DiffHour = 0)
DiffHour = %DiffHour%
If (DiffMinutes < 10)
DiffMinutes = 0%DiffMinutes%
If (DiffSeconds < 10)
DiffSeconds = 0%DiffSeconds%

Progress, B1 zy42 fm46 wm100 w301 h156 CB0 CWF0F0F0 CT000000,, %Expires%
If (DiffHour = 0)
Progress, 2:B zy0 zx0 fm18 wm100 x994 y477 w100 h24 CB0 CWF0F0F0 CT550000,, %DiffMinutes%:%DiffSeconds%
Else
Progress, 2:B zy0 zx0 fm18 wm100 x994 y477 w100 h24 CB0 CWF0F0F0 CT550000,, %DiffHour%:%DiffMinutes%:%DiffSeconds%

SetTimer, UpdateProgressSleep, 1000
Return
 
UpdateProgressSleep:
DiffHour = %Aim%
DiffHour -= A_Now, Hours
DiffMinutes = %Aim%
DiffMinutes -= A_Now, Minutes
DiffMinutes := DiffMinutes - 60 * DiffHour
DiffSeconds = %Aim%
DiffSeconds -= A_Now, Seconds
DiffSeconds := DiffSeconds - 60 * ( DiffMinutes + 60 * DiffHour )

If (DiffHour = 0)
DiffHour = %DiffHour%
If (DiffMinutes < 10)
DiffMinutes = 0%DiffMinutes%
If (DiffSeconds < 10)
DiffSeconds = 0%DiffSeconds%

Progress,  , %Expires%
If (DiffHour = 0)
Progress, 2:  ,, %DiffMinutes%:%DiffSeconds%
Else
Progress, 2:  ,, %DiffHour%:%DiffMinutes%:%DiffSeconds%

If (DiffHour = 00 and DiffMinutes = 00 and DiffSeconds = 00)
{
SetTimer, UpdateProgressSleep, Off
}
Return


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], Rohwedder, william_ahk and 48 guests