EnvSub with incorrect timestamp

Report problems with documented functionality
teadrinker
Posts: 2056
Joined: 29 Mar 2015, 09:41
Contact:

EnvSub with incorrect timestamp

02 Apr 2018, 15:32

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
Last edited by teadrinker on 02 Apr 2018, 20:54, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: EnvSub with incorect timestamp

02 Apr 2018, 15:55

- 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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
joefiesta
Posts: 387
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: EnvSub with incorect timestamp

02 Apr 2018, 17:16

@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"
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: EnvSub with incorect timestamp

02 Apr 2018, 17:50

- 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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
teadrinker
Posts: 2056
Joined: 29 Mar 2015, 09:41
Contact:

Re: EnvSub with incorect timestamp

02 Apr 2018, 18:21

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.
User avatar
Xtra
Posts: 2038
Joined: 02 Oct 2015, 12:15

Re: EnvSub with incorrect timestamp

02 Apr 2018, 23:11

I use it like so:

Code: Select all

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

HTH
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: EnvSub with incorrect timestamp

02 Apr 2018, 23:44

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.
fatodubs
Posts: 4
Joined: 20 Sep 2017, 18:53

Re: EnvSub with incorrect timestamp

11 Apr 2018, 13:52

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).

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 2 guests