Problem with os.date?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with os.date?

Nick Gammon
I was browsing through the code for os.date and spotted the extra feature - not mentioned in the book, but in the reference manual, that you can use "!" as the first character to use UTC rather than local time.

However if you use that character only, rather than get the default date string (%c) in UTC format you get an error about the format being too long:

print (os.date ("!")) --> 'date' format too long

That message is slightly confusing. Perhaps:

* Change to %c if the string is empty after removing the !

or

* Give an error 'no date string' or similar if the string is empty after removing the !

- Nick

Reply | Threaded
Open this post in threaded view
|

Re: Problem with os.date?

Roberto Ierusalimschy
> I was browsing through the code for os.date and spotted the extra  
> feature - not mentioned in the book, but in the reference manual,  
> that you can use "!" as the first character to use UTC rather than  
> local time.
> 
> However if you use that character only, rather than get the default  
> date string (%c) in UTC format you get an error about the format  
> being too long:
> 
> print (os.date ("!")) --> 'date' format too long
> 
> That message is slightly confusing. Perhaps:
> 
> * Change to %c if the string is empty after removing the !
> 
> or
> 
> * Give an error 'no date string' or similar if the string is empty  
> after removing the !

Actually, the message is more than "slightly confusing"; it is plainly
wrong :)

We will fix that, but it seems that the behavior of os.date("!") should
be coherent with that of os.date(""): that is, it should return the
empty string.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Problem with os.date?

Nick Gammon

On 16/09/2006, at 12:34 AM, Roberto Ierusalimschy wrote:

We will fix that, but it seems that the behavior of os.date("!") should
be coherent with that of os.date(""): that is, it should return the
empty string.

Actually it doesn't, and is just as confusing:

> print (os.date (""))
stdin:1: 'date' format too long
stack traceback:
        [C]: in function 'date'
        stdin:1: in main chunk
        [C]: ?


The behaviour for a nil argument is the default format of %c.

> print (os.date ())
Sat Sep 16 10:29:49 2006
>

You could argue that an empty string should return an empty string, including the case of the string "!".

Alternatively, you could argue that the string "!" is intended to mean "!%c", although I suppose if you really mean that you may as well put it there. :)

- Nick

Reply | Threaded
Open this post in threaded view
|

Re: Problem with os.date?

Roberto Ierusalimschy
> On 16/09/2006, at 12:34 AM, Roberto Ierusalimschy wrote:
> 
> >We will fix that, but it seems that the behavior of os.date("!")  
> >should
> >be coherent with that of os.date(""): that is, it should return the
> >empty string.
> 
> Actually it doesn't, and is just as confusing:
> 
> [...]

After the fix, I mean.

-- Roberto