Cannot understand MSVC use of the tset function using the TZ envvariable

P

Pep

I put together this small test program to test the msvc 8 use of
timezones and am not getting the expected results. The setting of the
TZ env variable is supposed to be tzn[+ | -]hh[:mm:ss][dzn], where
both tzn and dzn are 3 characters long.

MSDN claims that if I put in EST5EDT as the argument to _putenv_s,
then I will get back 1 for the daylight variable, 1800 for the
timezone variable and EST for the tzname variable, yet the help pages
that come with MSVC 5 claim that I will get 69 for the daylight
variable with other variables set to the same values as claimed by
MSDN. So which one is correct?

When I run this program I do actually get 69 for the daylight variable
when I put in EST5EDT for the argument.

The documentation for the function claims that the daylight variable
will be non zero, with the default being 1, which is not very helpful
to solve this problem?

Now I am in the UK so am enterring GMT0BST as the argument and get 66
in the daylight variable, 0 in the timezone variable and GMT in the
tzname variable.

Actually I have played about with the dzn portion of the cli argument
and it appears that the daylight variable is set to the ascii value of
the first character of dzn!

Help, how the hell am I supposed ot understand what is going on here?

#include <time.h>
#include <iostream>

class testTimeZone
{
public:
/**
* Default ctor.
*/
testTimeZone();
/**
* Default dtor.
*/
~testTimeZone();
/**
* This is the main operator which will check event times.
* @parameter argc the number of cli arguments
* @parameter argv the cli arguments
*/
void testTimeZone::eek:perator()(int argc, char **argv);
};

testTimeZone::testTimeZone()
{
// start of run
std::cout << "default ctor entered" << std::endl;

// end of run
std::cout << "default ctor exited" << std::endl;
}

testTimeZone::~testTimeZone()
{
// start of run
std::cout << "default dtor entered" << std::endl;

// end of run
std::cout << "default dtor exited" << std::endl;
}

void testTimeZone::eek:perator()(int argc, char **argv)
{
// start of run
std::cout << "operator() entered" << std::endl;

if ((argc == 2) && (_putenv_s("TZ", argv[1]) != 0))
// error setting timezone
{
std::cout << "Unable to set TZ" << std::endl;
}
else
// timezone set so continue
{
int daylight;
long timezone;
char tzname[100];
size_t s;

// initialize the time library
_tzset();
// get the daylight saving flag
_get_daylight(&daylight);
// get the timezone
_get_timezone(&timezone);
// get the timezone name
_get_tzname(&s, tzname, sizeof(tzname), 0);

std::cout
<< "daylight saving flag ["
<< daylight
<< "] time zone ["
<< timezone
<< "] "
<< tzname
<< std::endl;
}

// end of run
std::cout << "operator() exited" << std::endl;
}

int main(int argc, char **argv)
{
// instantiate the class
testTimeZone TestTimeZone;

// execute the class
TestTimeZone(argc, argv);

// finished
return(0);
}
 
A

anon

Pep said:
I put together this small test program to test the msvc 8 use of
timezones and am not getting the expected results. The setting of the
TZ env variable is supposed to be tzn[+ | -]hh[:mm:ss][dzn], where
both tzn and dzn are 3 characters long.

MSDN claims that if I put in EST5EDT as the argument to _putenv_s,
then I will get back 1 for the daylight variable, 1800 for the
timezone variable and EST for the tzname variable, yet the help pages
that come with MSVC 5 claim that I will get 69 for the daylight
variable with other variables set to the same values as claimed by
MSDN. So which one is correct?

When I run this program I do actually get 69 for the daylight variable
when I put in EST5EDT for the argument.

The documentation for the function claims that the daylight variable
will be non zero, with the default being 1, which is not very helpful
to solve this problem?

Now I am in the UK so am enterring GMT0BST as the argument and get 66
in the daylight variable, 0 in the timezone variable and GMT in the
tzname variable.

Actually I have played about with the dzn portion of the cli argument
and it appears that the daylight variable is set to the ascii value of
the first character of dzn!

Help, how the hell am I supposed ot understand what is going on here?

Don't know. Just say NO to windows

btw you might be off-topic here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top