Date Formatting Issue

Developer: DOSLib
Summary: Discusses a DOSLib date formatting issue.

Question

Any idea why DOSLib (AutoCAD 2011 64-bit) would give the following error?

Command: (dos_strformatdate "%m/%d/%y" (dos_date))
Application error : Bad argument type nil

Answer

This is an odd error, because previous year values work just fine. For example:

Command: (dos_strformatdate "%m/%d/%y" '(2008 7 22))
"07/22/08"
 
Command: (dos_strformatdate "%m/%d/%y" '(2009 7 22))
"07/22/09"

But when you do this year, you get an error:

Command: (dos_strformatdate "%m/%d/%y" '(2010 7 22))
Application ERROR: Bad argument type

Note, this is an error generated by the AutoLISP interpreter - the dos_strformatdate function is never called in this instance. Is is probable that the number “2010” is a reserved symbol or a DXF code.

There are two ways to work around the problem. The first is just to grow the list with more integers so the AutoLISP interpreter does not identify it as something reserved. For example, this works:

Command: (dos_strformatdate "%m/%d/%y" '(2010 7 22 1 2 3))
"07/22/10"

You can to this in two steps:

Command: (setq date (append (dos_date) '(1 2 3)))
(2010 7 22 1 2 3)
 
Command: (dos_strformatdate "%m/%d/%y" date)
"07/22/10"

The other option is to specify the date values a real numbers, not integers. For example:

Command: (dos_strformatdate "%m/%d/%y" '(2010.0 7 22))
"07/22/10"

Building this list from the list returned by dos_date would not be hard, but it would be more work than just appending a few integers.