Can't restrict dates in DateTime and MonthCal

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
autoexec
Posts: 24
Joined: 20 Feb 2023, 22:38

Can't restrict dates in DateTime and MonthCal

Post by autoexec » 21 Feb 2023, 04:04

Hi, I'm new to v2 and converting my v1 scripts to v2 one by one.
I have a trouble using the date range in MonthCal and DateTime.
I think it may be a bug? but i'm not sure what it really is.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
#Warn All

; v2
MinDate := SubStr(DateAdd(A_YYYY A_MM A_DD, -1, "D"), 1, 8)
MaxDate := SubStr(DateAdd(A_YYYY A_MM A_DD, 1, "D"), 1, 8)
MyGui := Gui()

; can't restrict minimum date.
MyGui.AddMonthCal("Range" MinDate "-" MaxDate)
MyGui.AddDateTime("wp 1 Range" MinDate "-" MaxDate)

; "Invalid option" error occurred. but documents say that the minimum or maximum may be omitted.
;MyGui.AddMonthCal("Range" MinDate "-")
;MyGui.AddDateTime("wp 1 Range" MinDate "-")

MyGui.OnEvent("Close", (*) => ExitApp())
MyGui.Show()

; v1 code. this works in v1.
;MinDate := MaxDate := A_YYYY A_MM A_DD
;MinDate += -1, D
;MinDate := SubStr(MinDate, 1, 8)
;MaxDate += 1, D
;MaxDate := SubStr(MaxDate, 1, 8)
;Gui, Add, MonthCal, Range%MinDate%-%MaxDate% ; ok
;Gui, Add, DateTime, wp 1 Range%MinDate%-%MaxDate% ; ok
;Gui, Add, MonthCal, Range%MinDate%- ; ok
;Gui, Add, DateTime, wp 1 Range%MinDate%- ; ok
;Gui, Show
;Return

;GuiClose:
;ExitApp
pedro45_vs
Posts: 39
Joined: 28 Jun 2020, 18:46

Re: Can't restrict dates in DateTime and MonthCal

Post by pedro45_vs » 21 Feb 2023, 06:53

I think it's a bug. I tested it here and it didn't work either. It limits the maximum date but does not limit the minimum date
just me
Posts: 9576
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Can't restrict dates in DateTime and MonthCal

Post by just me » 21 Feb 2023, 09:26

I'm pretty sure it's a bug caused by changes to YYYYMMDDToSystemTime2() and /or YYYYMMDDToSystemTime() in :arrow: util.cpp. Maybe it's a problem with the zero terminator:

Code: Select all

			temp[_countof(temp) - 1] = '\0';
autoexec
Posts: 24
Joined: 20 Feb 2023, 22:38

Re: Can't restrict dates in DateTime and MonthCal

Post by autoexec » 22 Feb 2023, 01:36

Thank you all for testing and reporting it. I'm really happy to know what is wrong. :D
Post Reply

Return to “Ask for Help (v2)”