os.time, os.date, os.ts.time and os.ts.date

Dealing with dates and times is one of the most deceptively simple yet surprisingly complex problems in software. iNTERFACEWARE is not the first company to face challenges negotiating these issues. Hopefully, this article will help clarify why we altered the standard Lua os.time and os.date functions.

The standard Lua implementation of os.time and os.date uses Unix Epoch time. This measures dates in the number of seconds since 1st January 1971. On many operating systems, this works just fine. Any dates before 1971 are represented using negative numbers, and by using a 64-bit integer to store the number of seconds, this provides a fine, practical range of dates.

The problem? We discovered that, when using some versions of Windows, time functions did not work for dates before 1971. Instead, os.time would return nil for dates before 1st January 1971.< We tried to fix this problem by replacing the standard implementation of os.date and os.time with a new implementation that used a IEEE floating point number measuring the number of days since December 30th 1899.

In retrospect, this was not the best decision. We discovered other issues with the new implementation when trying to convert dates into co-ordinated universal time (UTC) and daylight savings.

With the launch of Iguana 5.5.1, we took a step back and tried a different approach. This time, we changed the implementation of os.date and os.time to include a ‘userdata’ defined object so that our customers could address these issues correctly. We also brought back the original standard Lua implementations of os.date and os.time, but we renamed these functions os.ts.date and os.ts.time to avoid conflicts.

What does this mean for you? Essentially, if you want the Iguana Translator to behave in the same way as bulk standard Lua, then the following code snippet will do the job:

os.time = os.ts.time
os.date = os.ts.date

But what functions should you use to solve date/time problems? The answer will depend on precisely what problem you are trying to solve.

Don’t worry, we will help. We’d like to use the Iguana user forums, this wiki and our standard support system as an open, transparent way to work co-operatively with you to solve specific date/time related problems. In other words, just drop us a line. We are more than happy to help you implement solutions specific to your date/time problems, and show you how to use these APIs.

In the meantime, I am happy to assure you that as of 5.5.1, we are freezing our current functions with their existing functionality. If we do introduce any additional functionality, we will do it by adding additional APIs rather than changing the existing ones.

Again, if you come across a specific problem that you need help with (time-related or otherwise), please do not hold back! We would be happy to assist you in finding specific solutions that will help you get your work done.

Eliot Muir
CEO,

iNTERFACEWARE