473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

why does _tzset return void?

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
7 3041
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
...I don't know of a standard...

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

May 18 '06 #3
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
15
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
2
by: Besta | last post by:
Hello all, I am having trouble creating a windows service with a timer. Everything seems to go ok but the elapsed event does not fire.Can anyone shed any light on this, may be something simple as...
21
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no...
2
by: JoeC | last post by:
Why does this crash? I am passing pointers around but I am confused why this dosn't work. This is a fairy long program and I hope I am posting relevent parts class space{ char gchar; graphic...
48
by: avasilev | last post by:
Hi all, my question is: if i allocate some memory with malloc() and later free it (using free()), is there a possibility that a consequent malloc() will allocate memort at the same starting...
13
by: Protoman | last post by:
I'm getting an error: 10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i < (+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end ()' Code: Enigma.hpp...
40
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
1
by: HarishAdea | last post by:
Hi, I am trying to run the JAVA pgm, but it is giving error as "selection does not contain a main type". The filename is "ScoreLeadSummary.java" when i try to run it or debug,it gives the pop...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.