mktime and time_t

Hello All,

Is QNX 6’s time_t still a signed 32 bit field? I thought it was unsigned
giving a maximum date of around 2106.

When I plug in numbers into my struct tm and then call mktime(), mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it should
be in 2038 when it fails, correct? Then to make it weirder, I can send the
same values to asctime() and it prints the string up to 2038.

What exactly is the maximum time allowed in QNX 6 and why is mktime()
returning an error in 2036?

TIA,

Jim

P.S. Why isn’t time_t a 32 unsigned? Heck for that matter why not Int64_t.
:slight_smile:

Jim Lambert <jlambert@futurex.com> wrote:

Hello All,

Is QNX 6’s time_t still a signed 32 bit field?

Yes, it is.

I thought it was unsigned giving a maximum date of around 2106.

No. In fact, QNX6 would be non-compliant if ti were an unsigned
value.

When I plug in numbers into my struct tm and then call mktime(), mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it should
be in 2038 when it fails, correct? Then to make it weirder, I can send the
same values to asctime() and it prints the string up to 2038.

Hm… don’t know why mktime if failing early. That needs a bit of
testing.

What exactly is the maximum time allowed in QNX 6 and why is mktime()
returning an error in 2036?

I think the maximum time allowed in QNX6 is sometime in the 2500s. QNX6
represents time internally as a 64-bit nano-second value.

Some of the libraries, especially ones using time_t, will fail earlier,
because how they are defined runs out earlier.

TIA,

Jim

P.S. Why isn’t time_t a 32 unsigned? Heck for that matter why not Int64_t.
:slight_smile:

Because, when it was defined, it seemed important to be able to represent
times BEFORE 1970, and when it was defined nobody was doing 64-bit Unix
machines.

-David

QNX Training Services
I do not answer technical questions by email.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:a1huuk$jo9$1@nntp.qnx.com

Jim Lambert <> jlambert@futurex.com> > wrote:
Hello All,

Is QNX 6’s time_t still a signed 32 bit field?

Yes, it is.

I thought it was unsigned giving a maximum date of around 2106.

No. In fact, QNX6 would be non-compliant if ti were an unsigned
value.

Look into platform/target_nto.h __TIME_T is defined as _Uint32t.
I remember reading somewhere that since 6.1 time_t is unsigned.

That is the same definition I saw.

Jim

“Mario Charest” <goto@nothingness.com> wrote in message
news:a1i0nt$eat$1@inn.qnx.com

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:a1huuk$jo9$> 1@nntp.qnx.com> …
Jim Lambert <> jlambert@futurex.com> > wrote:
Hello All,

Is QNX 6’s time_t still a signed 32 bit field?

Yes, it is.

I thought it was unsigned giving a maximum date of around 2106.

No. In fact, QNX6 would be non-compliant if ti were an unsigned
value.


Look into platform/target_nto.h __TIME_T is defined as _Uint32t.
I remember reading somewhere that since 6.1 time_t is unsigned.

I agree, I’m sure it was in the release notes for 6.0.1 or Patch A.

Rob Rutherford

“Jim Lambert” <jlambert@futurex.com> wrote in message
news:a1i15h$edq$1@inn.qnx.com

That is the same definition I saw.

Jim

“Mario Charest” <> goto@nothingness.com> > wrote in message
news:a1i0nt$eat$> 1@inn.qnx.com> …

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:a1huuk$jo9$> 1@nntp.qnx.com> …
Jim Lambert <> jlambert@futurex.com> > wrote:
Hello All,

Is QNX 6’s time_t still a signed 32 bit field?

Yes, it is.

I thought it was unsigned giving a maximum date of around 2106.

No. In fact, QNX6 would be non-compliant if ti were an unsigned
value.


Look into platform/target_nto.h __TIME_T is defined as _Uint32t.
I remember reading somewhere that since 6.1 time_t is unsigned.
\

“Jim Lambert” <jlambert@futurex.com> wrote in message
news:a1g9e8$5ks$1@inn.qnx.com

Is QNX 6’s time_t still a signed 32 bit field? I thought it was unsigned
giving a maximum date of around 2106.

When I plug in numbers into my struct tm and then call mktime(), mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it
should
be in 2038 when it fails, correct? Then to make it weirder, I can send
the
same values to asctime() and it prints the string up to 2038.

What exactly is the maximum time allowed in QNX 6 and why is mktime()
returning an error in 2036?

What version of QNX6 are you using, and can you post your code sample so we
can all have a look?


Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Here is one I whipped up in about 1 minute:

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>


int main(int argc, char* argv[])
{
struct tm lt;
time_t newtime;

/* Doesn’t fail */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 0; // January
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

/* Fails */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 6; // July
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

return(0);
}

“Adam Mallory” <amallory@qnx.com> wrote in message
news:a1kdto$eft$1@nntp.qnx.com

“Jim Lambert” <> jlambert@futurex.com> > wrote in message
news:a1g9e8$5ks$> 1@inn.qnx.com> …

Is QNX 6’s time_t still a signed 32 bit field? I thought it was
unsigned
giving a maximum date of around 2106.

When I plug in numbers into my struct tm and then call mktime(),
mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it
should
be in 2038 when it fails, correct? Then to make it weirder, I can send
the
same values to asctime() and it prints the string up to 2038.

What exactly is the maximum time allowed in QNX 6 and why is mktime()
returning an error in 2036?

What version of QNX6 are you using, and can you post your code sample so
we
can all have a look?


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

/* Better example showing asctime printing correctly for both dates */

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <limits.h>


int main(int argc, char* argv[])
{
struct tm lt;
time_t newtime;

/* Doesn’t fail */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 0;
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
printf(“String time is %s\n”, asctime(&lt));
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

/* Fails */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 6;
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
printf(“String time is %s\n”, asctime(&lt));
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);


exit(0);
}

lol I really need to read the whole message before posting. This is on the
latest release of QNX 6 that I know of which is 6.1.a (I think that is the
terminology).

Jim

“Jim Lambert” <jlambert@futurex.com> wrote in message
news:a1kh2b$963$1@inn.qnx.com

Here is one I whipped up in about 1 minute:

#include <stdlib.h
#include <unistd.h
#include <stdio.h
#include <time.h
#include <limits.h


int main(int argc, char* argv[])
{
struct tm lt;
time_t newtime;

/* Doesn’t fail */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 0; // January
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

/* Fails */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 6; // July
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

return(0);
}

“Adam Mallory” <> amallory@qnx.com> > wrote in message
news:a1kdto$eft$> 1@nntp.qnx.com> …
“Jim Lambert” <> jlambert@futurex.com> > wrote in message
news:a1g9e8$5ks$> 1@inn.qnx.com> …

Is QNX 6’s time_t still a signed 32 bit field? I thought it was
unsigned
giving a maximum date of around 2106.

When I plug in numbers into my struct tm and then call mktime(),
mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it
should
be in 2038 when it fails, correct? Then to make it weirder, I can
send
the
same values to asctime() and it prints the string up to 2038.

What exactly is the maximum time allowed in QNX 6 and why is mktime()
returning an error in 2036?

What version of QNX6 are you using, and can you post your code sample so
we
can all have a look?


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

\

I took a quick look at the code for mktime() (avail on public cvs) and
noticed that it converts your broken down time into #of secs since 1900.
Now since an uint32 can’t hold that, a double was used (would not have been
my choice) to hold this number. What goes wrong is that is checks that this
number (from 1900) doesn’t exceed the max of a time_t, which is does with
your example date. This should be fixed in a future release.

The reason asctime() works, is simple, it doesn’t have to calculate epoc
time.


Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>
“Jim Lambert” <jlambert@futurex.com> wrote in message
news:a1khcd$9qf$1@inn.qnx.com

lol I really need to read the whole message before posting. This is on
the
latest release of QNX 6 that I know of which is 6.1.a (I think that is the
terminology).

Jim

“Jim Lambert” <> jlambert@futurex.com> > wrote in message
news:a1kh2b$963$> 1@inn.qnx.com> …
Here is one I whipped up in about 1 minute:

#include <stdlib.h
#include <unistd.h
#include <stdio.h
#include <time.h
#include <limits.h


int main(int argc, char* argv[])
{
struct tm lt;
time_t newtime;

/* Doesn’t fail */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 0; // January
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

/* Fails */
lt.tm_year = 2036 - 1900;
lt.tm_mon = 6; // July
lt.tm_mday = 15;
lt.tm_hour = 12;
lt.tm_min = 15;
lt.tm_sec = 0;
newtime = mktime(&lt);
printf(“Newtime %d\n”,newtime);

return(0);
}

“Adam Mallory” <> amallory@qnx.com> > wrote in message
news:a1kdto$eft$> 1@nntp.qnx.com> …
“Jim Lambert” <> jlambert@futurex.com> > wrote in message
news:a1g9e8$5ks$> 1@inn.qnx.com> …

Is QNX 6’s time_t still a signed 32 bit field? I thought it was
unsigned
giving a maximum date of around 2106.

When I plug in numbers into my struct tm and then call mktime(),
mktime()
fails (returns -1) in early 2036. Even if it was using a signed, it
should
be in 2038 when it fails, correct? Then to make it weirder, I can
send
the
same values to asctime() and it prints the string up to 2038.

What exactly is the maximum time allowed in QNX 6 and why is
mktime()
returning an error in 2036?

What version of QNX6 are you using, and can you post your code sample
so
we
can all have a look?


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net



\