0

I'm writing Lua (5.3) in a Windows environment; the result will be used in many countries so file handling has to cater for multiple locales (which rules out the lfs and Penlight libraries) and also many date formats (as selected by the user).

I'm accessing files using luacom and Microsoft FileObject, which eliminates problems with file names, but I'm having difficulty with the DateLastModified property, which is returned in text.

I need to compare the DateLastModified for many hundreds of files to determine which is the latest.

One technique I've considered would involve temporarily setting (via the registry) the PC's Short Date format to something predictable that can be simply parsed such as "yyyy-MM-dd" (and resetting it afterwards) but I'm instinctively averse to messing with the user's registry settings, especially those that have ramifications outside my program.

I could copy each file to a temporary file with a name that allows lfs to get the modification data as an integer number of seconds, but that would seriously impact the run-time of what's supposed to be a fairly basic utility.

Is there a solution I've overlooked, or am I going to have to choose the least worst option? Note: I'm quite restricted in the libraries available in the target environment.

3

1 Answer 1

0

Although the default behaviour of Luacom is to return a Date as a text string (based on the current locale), it is possible to modify this behaviour:

3.4.6 DATE type When converting from COM to Lua, the default behavior is to transform DATE values to strings formatted according to the current locale. The converse is true: LuaCOM converts strings formatted according to the current locale to DATE values. The script can change the conversion from strings to tables by setting the DateFormat field of the luacom table (the LuaCOM namespace) to the string "table". The table will have Day, DayOfWeek, Month, Year, Hour, Minute, Second, and Milliseconds fields. To return the conversion to strings, set the DateFormat field to "string". Be careful with this feature, as it may break compatibility with other scripts.

From Luacom documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.