Page 1 of 1

EnvSub with incorrect timestamp

Posted: 02 Apr 2018, 15:32
by teadrinker
Documents wrote:If either Var or Value is an invalid timestamp or contains a year prior to 1601, Var will be made blank to indicate the problem.
If I launch the code

Code: Select all

time := A_Now
time -= 1600, s
MsgBox, % time
I get the error message instead of blank variable.

Image

AHK 1.1.28.1 64-bit
Windows 7 64

Re: EnvSub with incorect timestamp

Posted: 02 Apr 2018, 15:55
by jeeswg
- EnvSub and its -= equivalent give you the difference between 2 dates, 1600 is a date outside the range, so should cause an error.
- Since you agree that it should cause an error, there doesn't appear to be a bug. Are you saying that AHK is wrong to show an error message, and that that is a 'bug'?
- (Whether errors should be silent or explicit is up for debate. AHK v2 is slightly stricter than AHK v1, and shows more error messages, which I think, on balance, is probably for the best.)

Code: Select all

q:: ;get number of seconds since 1601
vDate := A_Now
vDate -= 1601, Seconds

DllCall("kernel32\GetSystemTimeAsFileTime", Int64P,vIntervalsUTC)
DllCall("kernel32\FileTimeToLocalFileTime", Int64P,vIntervalsUTC, Int64P,vIntervalsLocal)

MsgBox, % vDate "`r`n" (vIntervalsLocal//10000000)
return
- Ah, actually, I see, it appears to be working contrary to what's stated in the documentation.
- The script below works in accordance with what the documentation says. A blank variable, no error message.
- So then this becomes a semantic dispute. While the script is running, AHK behaves as documented. But that bit of the documentation omits to say that if certain errors are spotted in the checking stage, the script will never run.

Code: Select all

w::
vYear := 1600
vDate := A_Now
vDate -= vYear, Seconds
MsgBox, % vDate ;(blank)
return

Re: EnvSub with incorect timestamp

Posted: 02 Apr 2018, 17:16
by joefiesta
@jeeswg: I strongly disagree.

1. Why include something using DLL calls? That has nothing to do with this person's problem.
2. Your script, the second, does INDEED work as documented. But, that too is not the point.

you almost hit on the hit with just this: "Ah, actually, I see, it appears to be working contrary to what's stated in the documentation."
Except, I think it should be "Ah, actually, I see, it works contrary to what's stated in the documentation." And, this is what the person said in the first place.

3. It is not a "semantic dispute". Pure and simple

Either 1) It is a bug (which I believe it is) or 2) the documentation is incorrect.

The fact that your second script does work as documented and his does not indicates IT SHOULD BE CONSIDERED A BUG because the documentation says the 2 ways of subtracting time ARE the same: "Sets a variable to itself minus the given value (can also compare date-time values). Synonymous with: Var -= Value"

Re: EnvSub with incorect timestamp

Posted: 02 Apr 2018, 17:50
by jeeswg
- I provided the DllCall code for tests relating to edge cases.
- It is a semantic dispute, since you've just disputed it, and I think I know what the eventual outcome is going to be (I've been in this situation before). In fact, it's two semantic disputes, you're disputing whether this is in fact a dispute.
- There are grounds to say that the documentation could be clearer, and grounds to say that the documentation is and was correct.

Re: EnvSub with incorect timestamp

Posted: 02 Apr 2018, 18:21
by teadrinker
Hi, jeeswg

In my real code the timestamp is in the variable, of course. I needed to validate it and compare it with the current time, and I decided to try by using a simple example first. I didn't think there was a difference beetween a variable and a numeric value. My problem is solved, but since there is a discrepancy between the documentation and the actual behavior of the script, I consider it a bug.

Re: EnvSub with incorrect timestamp

Posted: 02 Apr 2018, 23:11
by Xtra
I use it like so:

Code: Select all

time += -1600, s
MsgBox, % time
Give it a try.

HTH

Re: EnvSub with incorrect timestamp

Posted: 02 Apr 2018, 23:44
by lexikos
Scripts - Introduction
...
During loading, the script is optimized and validated. Any syntax errors will be displayed, and they must be corrected before the script can run.
If the command executes, it behaves as documented. In the case of a detected syntax error, no part of the script executes.

Re: EnvSub with incorrect timestamp

Posted: 11 Apr 2018, 13:52
by fatodubs
I ended up here after searching to report the bug, as well, but discovered that the issue is mine. Considering the shortcut suggest they are the same thing only with positive or negative movement, maybe highlighting the distinction in the documentation would be helpful.

With more careful reading, I realized that the TimeUnits sections are different in several ways, but these two lines - one from each description - brought it home:
  • To add or subtract a certain number of seconds, minutes, hours, or days from a timestamp, use EnvAdd (or its shorthand) (subtraction is achieved by adding a negative number).
  • To calculate the amount of time between two timestamps, use EnvSub (or its shorthand).