problem with timestamp, why?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

problem with timestamp, why?

Post by neutrox »

Code: Select all

   input $par, "Edit Timestamp parameters, please:", ' m, "2009-03-21 15:32:27"'; timestamp $par;
Someone please explain me why timestamp is failing with this simple one, stamping current time instead of specified by input?

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: problem with timestamp, why?

Post by nas8e9 »

With the proviso that I'm not a scripter, but the help file states that the timestamp is the *second* parameter; also, the first parameter controls which of the three dates (created, modified, accessed) is changed. When not specified, all three are set.

It seems that if no timestamp is specified, the current date and time are applied.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: problem with timestamp, why?

Post by Stefan »

The script and the command is correct and working. ("m" is the first para of the timestamp and not a para from input())
(only that "input" is an method "input()" since long)

The only possible problem i see, is with the date format of the "timestamp" command:

date [optional] must be in a format that the local system can understand;



Test your time format with
::msg "<date>";

Mine is
DD.MM.YYYY HH:mm:SS
but
YYYY-MM-DD HH:mm:SS
works to for timestamp.

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: problem with timestamp, why?

Post by neutrox »

Thanks for your answer stefan but that did not affected anything. very strange...

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: problem with timestamp, why?

Post by neutrox »

Just to clarify: if I use it in the direct order, address bar timestamp m, "2009-03-21 15:32:27" for instance, it just works fine.

PeterH
Posts: 2829
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: problem with timestamp, why?

Post by PeterH »

neutrox wrote:

Code: Select all

   input $par, "Edit Timestamp parameters, please:", ' m, "2009-03-21 15:32:27"'; timestamp $par;
Someone please explain me why timestamp is failing with this simple one, stamping current time instead of specified by input?
I needed some time to understand this...

...but I think I did?

It's so: you give one (that is the first) parameter to the timestamp command. This is the parameter [type]! Contents: m, "...date...".
You don't specify a second parameter, i.e. no [date]. The default for [date] is Now. :ugeek:

I'm convinced you cannot supply two parameters in one variable!
(Imagine a substr() function, where the text contains a ",": if this would be interpreted as 2 parameters...)

In other words: there is a difference between (here specified with constants):

Code: Select all

   timestamp 'm', '"...date..."';
   timestamp 'm, "...date..."';
You see: the first specifies 2 parameters, the second only 1.

And talking about functions: nowadays functions are documented as
$x = func(...parameters...); - while the form
func $x ...parameters...; is only for compatibility with veryvery old syntax. So I think it would be helpful to talk about the "input" function by using the current form $par = input(). This will help to prevent confusion.

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: problem with timestamp, why?

Post by neutrox »

Code: Select all

$par = input("Edit Timestamp parameters, please:", "System default is: <date> (format MATTERS!)<crlf>c - created, m - modified, a - accessed (00:00 as hour);<crlf>use in any combination/order or empty for all", ' m, "21/3/2009 15:32:27"'); 
timestamp $par;
Gives me the same.

And the stepped script displays timestamp m, "21/3/2009 15:32:27" which seems to be in accord with what you said plus works as stated ie from the address bar...

It would be difficult to me to enforce my script to follow your quoting method. Can you give it a fix them?

PeterH
Posts: 2829
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: problem with timestamp, why?

Post by PeterH »

neutrox wrote:

Code: Select all

$par = input("Edit Timestamp parameters, please:", "System default is: <date> (format MATTERS!)<crlf>c - created, m - modified, a - accessed (00:00 as hour);<crlf>use in any combination/order or empty for all", ' m, "21/3/2009 15:32:27"'); 
timestamp $par;
Gives me the same.

And the stepped script displays timestamp m, "21/3/2009 15:32:27" which seems to be in accord with what you said plus works as stated ie from the address bar...

It would be difficult to me to enforce my script to follow your quoting method. Can you give it a fix them?
Sorry: the basic problem is the same as before!

The last line is timestamp $par; This is the command "timestamp" with only one parameter, i.e. all text from $par is the first parameter! You must, by some means, separate it to two variables and specify them separately! E.g.

Code: Select all

   $par1 = gettoken($par, 1, ",");
   $par2 = gettoken($par, 2, ",");
   timestamp $par1, $par2;
Is it more clear this way?

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: problem with timestamp, why?

Post by neutrox »

Separator was ", " instead of "," (maybe unnecessary as the real problem was the next one) and quotes should have to go, then the problem was solved. Thanks!

PeterH
Posts: 2829
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: problem with timestamp, why?

Post by PeterH »

neutrox wrote:Separator was ", " instead of "," (maybe unnecessary as the real problem was the next one) and quotes should have to go, then the problem was solved. Thanks!
Sorry: I don't understand that...

Syntax defines, that "," as an operand separator may be combined with leading and trailing blanks. So:

Code: Select all

   $x=func($a,$b);        // is *identical*] to:
   $x = func( $a  ,  $b );
If you wanted to say that your initial code works, if you add some blank to the "," - then I'm convinced that this only works by chance!

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: problem with timestamp, why?

Post by neutrox »

neutrox wrote:
Separator was ", " instead of "," (maybe unnecessary as the real problem was the next one) and quotes should have to go, then the problem was solved. Thanks!
You're right.
Then the remaining problem was just with the quoting.

Code: Select all

   $par = input("Edit Timestamp parameters, please:", "System default is: <date> (format MATTERS!)<crlf>c - created, m - modified, a - accessed (00:00 as hour);<crlf>use in any combination/order or empty for all", " m, 21/3/2009 15:32:27");
   $par1 = gettoken($par, 1, ", ");
   $par2 = gettoken($par, 2, ", ");
   timestamp $par1, $par2;

PeterH
Posts: 2829
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: problem with timestamp, why?

Post by PeterH »

neutrox wrote:
neutrox wrote:
Separator was ", " instead of "," (maybe unnecessary as the real problem was the next one) and quotes should have to go, then the problem was solved. Thanks!
You're right.
Then the remaining problem was just with the quoting.

Code: Select all

   $par = input("Edit Timestamp parameters, please:", "System default is: <date> (format MATTERS!)<crlf>c - created, m - modified, a - accessed (00:00 as hour);<crlf>use in any combination/order or empty for all", " m, 21/3/2009 15:32:27");
   $par1 = gettoken($par, 1, ", ");
   $par2 = gettoken($par, 2, ", ");
   timestamp $par1, $par2;
Sorry to say: I understood it wrong, and so I said it wrong :roll:
(Now seeing this code I do understand!)

The real problem? You want to cheat - and fall in between different syntax rules! :shock:

Before I was talking about rules to separate operands.
But your logic first creates one string, and my primitive logic splits it by string-manipulation to 2 strings for 2 operands. And this splitting follows other rules!

In the original string, after the separator ",", (and as well before the leading "m",) there is a blank character! This will be kept in the separated strings - and as such be a part of both operands! I.e. the result will be as in

Code: Select all

   timestamp " m", " ...date...";
(Note the leading blanks in both operands!)

Your change for the splitting separator to ", " leads to one blank trimmed from left of the second operand. But: that's correct only if there is exactly one blank! If there's none the split will not work at all, if there are two blanks then one will remain...
(...sorry: that's expected from cheating, isn't it?)
(And doesn't affect the " m" - that still can lead to problems...)

So what to do?
Either do separate inputs for both operands, and expect both to be entered exactly as needed.
Or continue to enter both as one string, and await exactly one combinations of blanks and delete them.
Or continue, but add logic to delete blanks of both operands by trim() function.

Code: Select all

   $par1 = trim(gettoken($par, 1, ","), " ");
   $par2 = trim(gettoken($par, 2, ","), " ");
   timestamp $par1, $par2;
It seems this way you are on a quite save side...

Post Reply