By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,543 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,543 IT Pros & Developers. It's quick & easy.

why does _tzset return void?

P: n/a
Hi all,

Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?

Other question: how to check the timezone is a valid one?

Thanks for all answers.

May 18 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
ge*************@yahoo.com wrote:
Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?
What's "_tzset"? I don't know of a standard function (implied by your
statement that it returns something) by that name. Could it be that
you're in a wrong newsgroup and need a platform-specific forum?
Other question: how to check the timezone is a valid one?


AFAICT, there is no standard function that sets (or gets) the zone,
you can only deduce it from the difference in time returned by gmtime
and localtime functions. Perhaps your OS allows it, then you need to
ask about that functionality in the newsgroup that deals with your OS.

Speaking of 'gmtime' and 'localtime', the specification does not claim
any time zone relation or even the fact that those functions return
a 'valid' time, only that they convert something 'time' returns to the
'tm' struct (broken down time struct).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 18 '06 #2

P: n/a
...I don't know of a standard...

http://msdn.microsoft.com/library/de...crt__tzset.asp

May 18 '06 #3

P: n/a
ge*************@yahoo.com wrote:
..I don't know of a standard...

http://msdn.microsoft.com/library/de...crt__tzset.asp


To know if it's standard or not, look in the description itself. An example
of
a standard function is here:

http://msdn.microsoft.com/library/de..._crt_clock.asp

Notice the 'compatibility' column in the table in the Requirements section.
And if it doesn't say ANSI there, it's not standard. You need to ask in the
OS newsgroup (or the compiler newsgroup) about a function like that.

HTH

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 18 '06 #4

P: n/a
ge*************@yahoo.com wrote:
Hi all,

Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?

Other question: how to check the timezone is a valid one?

Thanks for all answers.


On unix/linux, see:

man tzset

Here's a quote from the man page:

<quote>

Conforming to: SVID 3, POSIX, 4.3BSD

#include <time.h>

void tzset (void);

extern char *tzname[2];
extern long timezone;
extern int daylight;

The tzset() function initializes the tzname variable from the TZ
environment variable. This function is automatically called by the other
time conversion functions that depend on the time zone. In a SysV-like
environment it will also set the variables timezone (seconds West of
GMT) and daylight (0 if this time zone does not have any daylight
savings time rules, nonzero if there is a time during the year when
daylight savings time applies).

If the TZ variable does not appear in the environment, the tzname
variable is initialized with the best approximation of local wall clock
time, as specified by the tzfile(5)-format file localtime found in the
system timezone directory (see below). (One also often sees
/etc/localtime used here, a symlink to the right file in the system
timezone directory.)

If the TZ variable does appear in the environment but its value is
empty or its value cannot be interpreted using any of the formats
specified below, Coordinated Universal Time (UTC) is used.
</quote>

Larry
May 18 '06 #5

P: n/a
Larry I Smith wrote:
ge*************@yahoo.com wrote:
Hi all,

Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?

Other question: how to check the timezone is a valid one?

Thanks for all answers.


On unix/linux, see:

man tzset

Here's a quote from the man page:

<quote>

Conforming to: SVID 3, POSIX, 4.3BSD

#include <time.h>

void tzset (void);

extern char *tzname[2];
extern long timezone;
extern int daylight;

The tzset() function initializes the tzname variable from the TZ
environment variable. This function is automatically called by the other
time conversion functions that depend on the time zone. In a SysV-like
environment it will also set the variables timezone (seconds West of
GMT) and daylight (0 if this time zone does not have any daylight
savings time rules, nonzero if there is a time during the year when
daylight savings time applies).

If the TZ variable does not appear in the environment, the tzname
variable is initialized with the best approximation of local wall clock
time, as specified by the tzfile(5)-format file localtime found in the
system timezone directory (see below). (One also often sees
/etc/localtime used here, a symlink to the right file in the system
timezone directory.)

If the TZ variable does appear in the environment but its value is
empty or its value cannot be interpreted using any of the formats
specified below, Coordinated Universal Time (UTC) is used.
</quote>

Larry


Pay special attention to the last paragraph above.
the Timezone defaults to UTC (aka GMT) if the env variable is 'bad'.
It wouldn't do to have all of the time functions fail, just because
someone messed up an env variable; so UTC is used as a last resort.

On later versions of Windows, _tzset() uses the Windows Timezone
(the one set via the Control Panel) rather than a TZ env variable.

Larry
May 18 '06 #6

P: n/a
Larry I Smith wrote:
Larry I Smith wrote:
ge*************@yahoo.com wrote:
Hi all,

Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?

Other question: how to check the timezone is a valid one?

Thanks for all answers.


On unix/linux, see:

[...off-topic reply to an off-topic question redacted...]

Larry


Pay special attention to the last paragraph above.
[...more off-topic posting redacted...]

Larry


Dear Larry,

Please refrain from posting off-topic. You're doing a disservice to
both the original poster and the rest of the newsgroup, and you
probably don't realise that. If you're doing it on purpose, knowing
that it's a disservice, please do tell us, it will help us deal with
the situation.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 19 '06 #7

P: n/a
Victor Bazarov wrote:
Larry I Smith wrote:
Larry I Smith wrote:
ge*************@yahoo.com wrote:
Hi all,

Why doesn't _tzset return an error when the TZ environment
variable does not contain a valid timezone?

Other question: how to check the timezone is a valid one?

Thanks for all answers.

On unix/linux, see:

[...off-topic reply to an off-topic question redacted...]

Larry

Pay special attention to the last paragraph above.
[...more off-topic posting redacted...]

Larry


Dear Larry,

Please refrain from posting off-topic. You're doing a disservice to
both the original poster and the rest of the newsgroup, and you
probably don't realise that. If you're doing it on purpose, knowing
that it's a disservice, please do tell us, it will help us deal with
the situation.

V


Sorry.

This answer might have been more on-topic:

Because the timezone defaults to CUT (aka GMT) if all else fails.
Otherwise many of the standard functions declared in the <ctime>
header would not work - which is unacceptable.

Regards,
Larry
May 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.