localtime and gmtime returning the same value

295 views
Skip to first unread message

Josh Peterson

unread,
Feb 24, 2012, 10:31:36 PM2/24/12
to Native-Client-Discuss
I'm seeing what I believe is unexpected behavior using pepper_16 and
Chrome17.

I store a time_t value at one point, then I want to display it it
either UTC time or local time (US eastern time, in my case), depending
on a user setting. However when I do this in a unit test:

time_t current = time(NULL);
std::cout << "localtime: " << asctime(localtime(&current));
std::cout << "gmttime: " << asctime(gmtime(&current));

the result is:

localtime: Sat Feb 25 03:30:39 2012
gmttime: Sat Feb 25 03:30:39 2012

Running the same code compiled with VC10 results in this output:

gmttime: Sat Feb 25 03:26:23 2012
localtime: Fri Feb 24 22:26:23 2012

I believe the output from VC10 is correct, since my time zone is UTC -
5 hours. Why are localtime and gmttime returning the same value when
I run the code using NaCl? Is this the expected behavior? Thanks.

Bennet Yee (余仕斌)

unread,
Feb 25, 2012, 12:06:48 AM2/25/12
to native-cli...@googlegroups.com
when the time zone is unknown, localtime defaults to UTC.  NaCl does not expose the user's timezone offset to the application.  There is no time zone database -- in a glibc-based toolchain, this would require files /etc/localtime and /usr/share/zoneinfo/* to be available.  on unix machines, these files are updated periodically whenever leap seconds, daylight savings time changes, etc, are announced.  perhaps when we get support libraries like nacl_mounts more standardized/stabilized, we can get something like tzdata to work.

-bsy
 
--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To post to this group, send email to native-cli...@googlegroups.com.
To unsubscribe from this group, send email to native-client-di...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/native-client-discuss?hl=en.




--
bennet s yee
i usually don't capitalize due to mild tendonitis

Josh Peterson

unread,
Feb 25, 2012, 7:29:33 AM2/25/12
to Native-Client-Discuss
Bennet,

Thanks that clears things up!

Josh

On Feb 25, 12:06 am, Bennet Yee (余仕斌) <bennet....@gmail.com> wrote:

Victor Khimenko

unread,
Feb 25, 2012, 8:02:49 AM2/25/12
to native-cli...@googlegroups.com
Note that today you can send message to JavaScript and use Date() object there to get local time.

Sure, this is not a proper replacement for localtime() and friends (for one latency will be few orders of magnitude higher then latency of localtime() on most OSes) but should cover the most important cases.
Reply all
Reply to author
Forward
0 new messages