lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Aug 24, 2005 at 12:09:04AM +0200, steffenj wrote:
> out of my mind (cases could be outer way round, not sure):
> 
> os.date("%Y %M %D %h %m %s")
> 
> will give you:
> year month day hours minutes seconds
> 
> for more, see the Ansi C date function description, it should be possible to
> find that on the web
> 
> -----Ursprüngliche Nachricht-----
> Von: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] Im Auftrag von PA
> Gesendet: Dienstag, 23. August 2005 22:24
> An: Lua list
> Betreff: date arithmetic?
> 
> Hello,
> 
> How does one do date arithmetic in Lua?
> 
> Right now, I'm manipulating the os.date's table directly:
> 
> local aDate = os.date( "*t" )
> 
> print( os.date( "%x", os.time( aDate ) ) )
> 
> -- find the end of the month
> aDate.month = aDate.month + 1
> aDate.day = 0
> 
> print( os.date( "%x", os.time( aDate ) ) )
> 
>  > 08/23/05
>  > 08/31/05
> 
> Seems to work, but I'm not sure if this is by luck or design.. :)

actually both:
by design, since it is meant to work that way:
	it uses the mktime() function to make a time from struct tm
by luck, since mktime() seems to be not fully specified
	and at least implementations differ substantially in
	handling of illegal values.

e.g. a recent linux (i.e. glibc) mktime man page sez:
"
If  structure members are outside their legal interval,
they will be normalized (so that, e.g., 40 October  is
changed  into 9 November).
"
... which *could* one lead to assume that Nov 0ths
should be last of October


in short, do not rely on it unless you are going
to stick to your platform (i.e. libc *version* !).



cheers