Time class and signed unix time

Hi All

I am working on a project for embedded control for a device I am looking at selling. The device would include control based on time, and due to the nature of the product I anticipate it will just sit in the background doing it’s thing for years without customer interaction.

I have been using Time.now() to get the UnixTIme and put this into an unsigned integer for use by my program. The issue I am having is that I am now looking at the compiler warnings and it is saying that I am doing improper comparisons later in my code when I compare the unsigned Integer with Time.now(). From this, it looks like that Time.now() is returning an unsigned int.

Looking at the code, it appears that the type is defined as time_t, but unfortunately I have not yet been able to find the definition of time_t.

For me, using a signed integer means that the product will stop working in 2038, or in about 24 years. I know that might sound a long way away, but I would prefer not to build in issues like that into a product that I am hoping will still be working after that time. The issue for me is that my product would be wired into a permanently wired appliance in the house and I am guessing that at least 25% of devices will still be in service after that time.

I know this is not a high priority to fix, but it should probably be added to the list.

Thanks

Darryl

1 Like

@vk2tds, time_t is defined as INT32 which is exactly what you suspected. I have looked at the Arduino time libraries and time_t is defined as an unsigned long, ie UINT32. I will raise an issue to see if this the Spark time_t can be changed to UINT32. :smile:

UPDATE: The issue has been raised.

2 Likes

So time_t is defined at INT32 in core-common-lib/CC3000_Host_Driver/cc3000_common.h and the it looks like the CC3000 driver uses it as along with an INT32 number of microseconds as a timeout value.

I think the CC3000 should get renamed to a CC3000 specific name and a new time_t added elsewhere as UINT32.

3 Likes

Thanks for the replies.

Darryl