Page 1 of 1

problem with timestamp, why?

Posted: 09 Apr 2012 20:28
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?

Re: problem with timestamp, why?

Posted: 09 Apr 2012 20:41
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.

Re: problem with timestamp, why?

Posted: 09 Apr 2012 20:52
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.

Re: problem with timestamp, why?

Posted: 09 Apr 2012 21:46
by neutrox
Thanks for your answer stefan but that did not affected anything. very strange...

Re: problem with timestamp, why?

Posted: 09 Apr 2012 21:55
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.

Re: problem with timestamp, why?

Posted: 09 Apr 2012 22:50
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.

Re: problem with timestamp, why?

Posted: 09 Apr 2012 23:15
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?

Re: problem with timestamp, why?

Posted: 09 Apr 2012 23:34
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?

Re: problem with timestamp, why?

Posted: 09 Apr 2012 23:47
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!

Re: problem with timestamp, why?

Posted: 09 Apr 2012 23:58
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!

Re: problem with timestamp, why?

Posted: 10 Apr 2012 00:05
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;

Re: problem with timestamp, why?

Posted: 10 Apr 2012 00:47
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...