Domanda

I'm inserting a string variable to my MySQL table using this os.date() function call:

tSend["sDate"] = os.date( "%Y-%m-%d %X", Core.GetUserValue(v, 25) )

The table tSend is forwarded to another function which inserts it into the table.

This doesn't work as required. For eg. It'll insert 2013-01-31 12:59:59 instead of 2013-01-31 00:59:59 to the table. It happens to all the hours after the 1159 hours.

According to the Lua PiL book,

%X implies time (e.g., 23:48:10)

I can not use NOW() in my query as the time generated by Core.GetUserValue(v, 25) is a property of PtokaX and is given as User login time in seconds from 1.1.1970.

What can be the problem here? A simple lua code with

print( os.date("%Y-%m-%d %X", 1355586777) )

generates 2012-12-15 21:22:57 as output(where 1355586777 is the value I received from the Core.GetUserValue call).

I used to have %H:%M:%S instead of %X but I thought of using %X and it seems, I'll have to revert back.

È stato utile?

Soluzione

I think I found the error in the behavior.

I think it is maybe because PtokaX is written in C and then the lua scripts are called through it. Since, the strftime defines %X as

writes localized time representation (locale dependent)

This causes the time output to be in 12-hour format, instead of 24 hour. I'll still have to test it after 12 PM today.

P.S.

I don't know how to check the locale date format, but I'm assuming this is the only valid cause for this behavior.


I switched back to using os.date( "%Y-%m-%d %X" ) in my scripts.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top