Tcl Source Code

View Ticket
Login
Ticket UUID: cd25761979da7be2861f124c41956cb0f9945ca4
Title: clock command - "now" vs "-now"
Type: Bug Version: main
Submitter: oehhar Created on: 2024-07-25 12:52:45
Subsystem: 16. Commands A-H Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-07-28 19:52:15
Resolution: Fixed Closed By: sebres
    Closed on: 2024-07-28 19:52:15
Description:

Ashok wrote the following message on the core list:

% clock scan now
1721803544
% clock format now
bad seconds "now": must be -now or integer
% clock format -now

The above seems incongruous to me, why -now for format and “now” for scan?

Afaict, “-now” is really a value, not an option. And unlike options, it cannot appear at arbitrary points in the command, only in place of the time value.

Is there a rationale for the difference? If no, is it too late to change for 9.0? If too late for compatibility reasons, can clock format and clock add treat “now” and “-now” as synonyms with latter deprecated? (With a TIP of course)

User Comments: sebres added on 2024-07-28 19:52:15:

Fixed in [f602e32fc37910d1] for 8.7+, value -now retained to compat reasons to earlier versions and tclclockmod, but undocumented at the moment (excepting the TIP).


apnadkarni added on 2024-07-28 16:48:34:

I'm with Schelte on this one for exactly the reasons he described. It doesn't matter what the context for usage; in the user's mind it refers to current time and having to remember where to use "now" and where to use "-now" is unnecessary and confusing.

If "-now" needs to be maintained as a synonym for some reason (compatibility with 9.0 beta releases?) we can just leave it undocumented.


sbron added on 2024-07-27 19:56:44:

I have to disagree. It doesn't make sense. The [clock format] command takes one argument indicating which time value to format. Allowing some symbolic name to serve as a shorthand for the frequently used value [clock seconds] is useful. But that symbolic name still represents a value. So it should just be a simple symbolic name, like "now". It shouldn't be a "quasi" option that needs to be in a specific position and then disallows providing the value argument. (The statement that value becomes optional is not true. If both are provided, an error is thrown.)

Why introduce such a complicated set of rules when it could suffice to say that "the word 'now' may be used for timeVal to mean the current time".

So I definitely would say that "now" should at least be accepted in all the places where "-now" has recently been introduced. I also think that "-now" should be deprecated as soon as possible, because we should get rid of things that are not logical. In my opinion, "-now" deserves that qualification.


oehhar added on 2024-07-27 12:25:12:

Sergey, thank you for the explanation. That makes sense.

I hope, I did not disturb you within your holidays...

Thanks again, Harald


sebres added on 2024-07-26 19:02:29:

The new clock engine introduces new pseudo seconds value as quasi "option" -now, as a replacement for [clock seconds] supplied as a base.

This is also described in the TIP.

clock scan now is a free-scan form (without format) what was always able to parse "word" now... this has indirectly nothing to do with the -now "option" (which is normally applicable for clock format or clock add).

clock scan always uses base -now by default, but it can be surely supplied with -base parameter additionally (although doesn't make sense, because as already said by default it is now):

% clock scan "+1 month" -base -now
1724623200
% clock scan "+1 month"
1724623200
% clock scan "now +1 month"
1724623200
% clock scan "tomorrow +1 month"
1724709600

Just note that only free-scan form of clock scan accepts now (or tomorrow or whatever).

Anyway both have nothing to do with each others (one is a base value to format, add etc, another is a user input to scan).

> Afaict, “-now” is really a value, not an option.

Well, matter of taste probably. One can consider it as an option so that then commands clock add and clock format don't need a value (value becomes optional in that case).

However, I'm not against can to treat now and -now as synonyms (no idea it'd need a TIP again). But please without further deprecation of -now.


oehhar added on 2024-07-25 12:58:16:

Ashok, great to find that.

The TIP https://core.tcl-lang.org/tips/doc/trunk/tip/688.md only writes about "-now" not "now".

Thanks for branch [b5e6612557] I am also with you, that just "now" looks nicer.

Thank you, Harald