PDA

View Full Version : Reg: RogueWave - isDST() issue



Shakila
05-22-2008, 06:22 AM
Hi All,

I am using RWZone object and RWTime object to check whether a given Date is falling under DST or not when the server is in Non DST time.

I have created objRWTime with the date that falls in DST (ex. I have given 06052008) I have updated my TZ variable to MST7MDT and executed the objRWTime.isDST() method. This was returning 1.

But after that, I have created another objRWTime with the date that falls in NON DST (ex. I have given 12122008). I have updated my TZ variable to MST7 (because now I want to be in Non DST) and also I have updated my system's time to Nov, 10, 2008. Then I executed the objRWTime.isDST() method. But now the function is returning 0.

Please help me to find out how to check whether a date falls in DST when the Server is in NON DST.

Thanks in advance,
Shakila.

dean
05-22-2008, 07:13 AM
Shakila,

First of all how are you setting your RWZone variable? If you are using the default ( RWZone::local() ) then the default US Timezone rules will be applied to whatever you set your TZ variable even if it a non-DST timezone (MST7). You want the OS rules to be applied then you will need to use the RWZone::local( &RWZone::os() ) to install the underlying system's DST rule as your global local time.

Here is a sample:


<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h="">#include &lt;iostream&gt;<iostream><iostream>
#include </iostream></iostream></rw></rw></iostream></rw></rw></iostream>&lt;<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream>rw/zone.h</iostream></iostream></rw></rw></iostream></rw></rw></iostream>&gt;
<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream> #include </iostream></iostream></rw></rw></iostream></rw></rw></iostream>&lt;<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream>rw/rwtime.h</iostream></iostream></rw></rw></iostream></rw></rw></iostream>&gt;
<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream> #include </iostream></iostream></rw></rw></iostream></rw></rw></iostream>&lt;<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream>rw/rwdate.h</iostream></iostream></rw></rw></iostream></rw></rw></iostream>&gt;
<iostream><rw zone.h=""><rw rwtime.h=""><iostream><rw zone.h=""><rw rwtime.h=""><iostream><iostream><rw rwdate.h=""><rw rwdate.h="">
int main(int argc, char* argv[])
{
RWTime a(RWDate(1,2,2008),10,30,0);
RWTime b(RWDate(1,7,2008),10,30,0);
RWTime c(RWDate(1,11,2008),10,30,0);

std::cout << "RZone::local():" << std::endl;
RWZone::local();
std::cout << a << " a.isDST(): " << a.isDST() << std::endl;
std::cout << b << " b.isDST(): " << b.isDST() << std::endl;
std::cout << c << " c.isDST(): " << c.isDST() << std::endl << std::endl;

std::cout << "RWZone::local( &RWZone::os() ): " << std::endl;
RWZone::local( &RWZone::os() );
std::cout << a << " a.isDST(): " << a.isDST() << std::endl;
std::cout << b << " b.isDST(): " << b.isDST() << std::endl;
std::cout << c << " c.isDST(): " << c.isDST() << std::endl << std::endl;

return 0;
}Now for testing we will set TZ=US/Arizona which does not observe Daylight Savings:
$ export TZ=US/Arizona
$ t3
RZone::local():
02/01/08 10:30:00 a.isDST(): 0
07/01/08 10:30:00 b.isDST(): 1
11/01/08 10:30:00 c.isDST(): 1

RWZone::local( &RWZone::os() ):
02/01/08 10:30:00 a.isDST(): 0
07/01/08 09:30:00 b.isDST(): 0
11/01/08 09:30:00 c.isDST(): 0

Let me know if this helps answer your question about DST?</rw></rw></iostream></iostream></rw></rw></iostream></rw></rw></iostream>

Shakila
05-25-2008, 11:45 PM
Hi Dean,

Thanks for your reply. I am facing two issues:

---------------------------------------------------------------------
ISSUE 1 : Compilation issue
---------------------------------------------------------------------
When I ran the sample which you have given I was getting the following error so I have commented that line and ran it again by setting TZ=US/Arizona. But still it gives 0 for the date which falls in DST:
Error 221: "t1.C", line 19 # Member 'os' not declared in class RWZone ["/opt/aCC/include/rw/zone.h", line 167].
RWZone::local( &RWZone::os() );

I have compiled using a file called compile (using command "compile t1.C") which has the following content:
echo "MAKEING........${1}....."
executable=`echo ${1} | cut -d'.' -f1`
/opt/aCC/bin/aCC -D_REENTRANT -DD_PTHREAD -DRWSTD_MULTI_THREAD -DHPUX_11 +eh +DA2.0 +inst_implicit_include -Wl,+n -
Wl,+s -o $executable $1 -lpthread -lm -lrwtool

Output when TZ=US/Arizona
---------------------------
RZone::local():
02/01/08 10:30:00 a.isDST(): 0
07/01/08 10:30:00 b.isDST(): 0
11/01/08 10:30:00 c.isDST(): 0

Output when TZ=MST7MDT
---------------------------
RZone::local():
02/01/08 10:30:00 a.isDST(): 0
07/01/08 10:30:00 b.isDST(): 1
11/01/08 10:30:00 c.isDST(): 1

I want to use only default US Timezone rules irrespective of the TZ variable. But please observe I am getting 0 for all dates that falls in daylight when my TZ=US/Arizona and RZone::local().

------------------------------------------------
ISSUE 2 : Kindly have a a look at my test program:
------------------------------------------------
With the help of RWZoneSimple class object, I want to use only default US Timezone rules irrespective of the TZ variable.

#include <rw/zone.h>
#include <rw/rwtime.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>

int main(){

RWZoneSimple myZone = RWZoneSimple(RWZone::USMountain);

//RWCString myDateStr("02152008"); // NO DAYLIGHT
RWCString myDateStr("05302008"); // May 30 - DAYLIGHT

RWCString myTimeStr("05:00:00AM");

RWDate myDate(myDateStr);

RWTime *myTime = new RWTime(myDate, myTimeStr, myZone);

RWCString myDateAndTime = (*myTime).asString("%Y""%m""%d""%H""%M""%S.GMT", RWZone::utc());

cout << "myDateAndTime = " << myDateStr << myTimeStr << endl;
cout << "myDateAndTime in UTC = " << myDateAndTime << endl;

cout<<"myTime.isDST ------------>>>>>>>>>> " << (*myTime).isDST() << endl;

return 0;
}

I compile this program using "compile test.C". In this program I create the RWZone object by "RWZoneSimple myZone = RWZoneSimple(RWZone::USMountain);"

I have the DateString as "05302008" (May 30) which falls in Daylight.

Output when I set the TZ=MST7MDT:
-------------------------------------
shakila - op13 - /home/shakila/work> echo $TZ
MST7MDT
shakila - op13 - /home/shakila/work> ./trw
myDateAndTime = 0530200805:00:00AM
myDateAndTime in UTC = 20080530110000.GMT
myTime.isDST ------------>>>>>>>>>> 1

Output when I set the TZ=MST7 or TZ=US/Arizona:
--------------------------------------------------
shakila - op13 - /home/shakila/work> echo $TZ
US/Arizona
shakila - op13 - /home/shakila/work> ./test
myDateAndTime = 0530200805:00:00AM
myDateAndTime in UTC = 20080530110000.GMT
myTime.isDST ------------>>>>>>>>>> 0

I want to use only default US Timezone rules irrespective of the TZ variable. But please observe that when my TZ=MST7 or TZ=US/Arizona the output of (*myTime).isDST() is = 0.

Please Note: I am in India and my default TZ will be set to IST-5:30. So for testing these program I used set TZ to MST7MDT (to simulate that I am Daylight) or just MST7 (to simulate that I am NON-Daylight).

Kindly help me to resolve these issues.

Thanks,
Shakila.

Shakila
05-26-2008, 09:41 PM
Hi Dean,

Thanks for your reply. I want to check whether the given date is falling in DST or not irrespective of the TZ variable value which is set in my Server.

But when I compile your sample program I was getting an issue "os()" is not declared in zone.h. So I have commented that line and compiled. When I run the program only with Zone::local() this is the output:

Output when TZ=US/Arizona
---------------------------
RZone::local():
02/01/08 10:30:00 a.isDST(): 0
07/01/08 10:30:00 b.isDST(): 0
11/01/08 10:30:00 c.isDST(): 0

Output when TZ=MST7MDT
---------------------------
RZone::local():
02/01/08 10:30:00 a.isDST(): 0
07/01/08 10:30:00 b.isDST(): 1
11/01/08 10:30:00 c.isDST(): 1

I want to use only default US Timezone rules irrespective of the TZ variable. But please observe I am getting 0 for all dates that falls in daylight when my TZ=US/Arizona and RZone::local().

With the help of RWZoneSimple object and RWTime object, I want to use the default US Timezone rules irrespective of the TZ variable.

#include <rw/zone.h>
#include <rw/rwtime.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>

int main(){

RWZoneSimple myZone = RWZoneSimple(RWZone::USMountain);

//RWCString myDateStr("02152008"); // NO DAYLIGHT
RWCString myDateStr("05302008"); // May 30 - DAYLIGHT

RWCString myTimeStr("05:00:00AM");

RWDate myDate(myDateStr);

RWTime *myTime = new RWTime(myDate, myTimeStr, myZone);

RWCString myDateAndTime = (*myTime).asString("%Y""%m""%d""%H""%M""%S.GMT", RWZone::utc());

cout << "myDateAndTime = " << myDateStr << myTimeStr << endl;
cout << "myDateAndTime in UTC = " << myDateAndTime << endl;

cout<<"myTime.isDST ------------>>>>>>>>>> " << (*myTime).isDST() << endl;

return 0;
}

I compile this program using "compile test.C". In this program I create the RWZone object by "RWZoneSimple myZone = RWZoneSimple(RWZone::USMountain);"

I have the DateString as "05302008" (May 30) which falls in Daylight.

Output when I set the TZ=MST7MDT:
-------------------------------------
shakila - op13 - /home/shakila/work> echo $TZ
MST7MDT
shakila - op13 - /home/shakila/work> ./trw
myDateAndTime = 0530200805:00:00AM
myDateAndTime in UTC = 20080530110000.GMT
myTime.isDST ------------>>>>>>>>>> 1

Output when I set the TZ=MST7 or TZ=US/Arizona:
--------------------------------------------------
shakila - op13 - /home/shakila/work> echo $TZ
US/Arizona
shakila - op13 - /home/shakila/work> ./test
myDateAndTime = 0530200805:00:00AM
myDateAndTime in UTC = 20080530110000.GMT
myTime.isDST ------------>>>>>>>>>> 0

I want to use only default US Timezone rules irrespective of the TZ variable. But please observe that when my TZ=MST7 or TZ=US/Arizona the output of (*myTime).isDST() is = 0.

Please Note: I am in India and my default TZ will be set to IST-5:30. So for testing these program I used set TZ to MST7MDT (to simulate that I am Daylight) or just MST7 (to simulate that I am NON-Daylight).

Kindly help me to resolve this issue.

Thanks,
Shakila.

Patrick Happel
05-27-2008, 09:01 AM
Hello Shakila,

The issues that you are running into mostly seem to be due to not setting the local time zone correctly. You will need to make sure that RWZone::local() is set to a time zone and dst rule that are correct for you. The default value for RWZone::local() is RWZone::os(), which is determined by the TZ variable of your system - I believe this explains the dependence on TZ that you are seeing.

You should try setting RWZone::local() to a test time zone, with the US DST rules. For example:

RWZone::local( new RWZoneSimple( RWZone::Greenwich, RWZone::NoAm ) );

This sets the default time zone to be used by SourcePro classes to Greeenwich, with North American (ie, US) daylight saving time rules. Having a line like this at the start of your program should separate the DST values being calculated from the value of the TZ environment variable.

I've assumed that you are using the 'classic' RWZone defined in Edition 9 update 1 and earlier versions of SourcePro. If you are using the redesigned RWZone from Edition 10 of SourcePro, that uses the zoneinfo database, then the behavior will be different. Let me know if this is the case, or if you have additional questions.

Regards,
-Patrick

Shakila
05-28-2008, 07:15 AM
Hi Patrick,

Thanks a lot for your reply and this works fine now for my test program.

I have a doubt. This is a very huge product and in a middle of a huge functional flow I am setting this RWZone::local(). Is this setting is for the whole life of the program? What is the scope of this local() call?

Also could you please tell me how can I check whether we are using the 'classic' RWZone defined in Edition 9 update 1 and earlier versions of SourcePro OR we are using the redesigned RWZone from Edition 10 of SourcePro, that uses the zoneinfo database?

Thanks in advance,
Shakila.

Patrick Happel
05-29-2008, 12:26 PM
Hi Shakila,

I'm not certain about the scope of the RWZone::local() call, but I will see if I can find the answer.

If you are using a version of SourcePro earlier than Edition 10, you are definitely using the classic RWZone. The easiest way to tell if a build of SourcePro Edition 10 is using the zoneinfo database is to look in the base directory of the buildspace - if there is a 'zoneinfo' directory present, then the libraries are using the database. If you've built multiple times in the same directory, you will need to check the buildspec file for an individual build, and look for the 'tools-library.rwzone-mode=' entry. This entry will either say 'Use Classic Tools Time Zones' or 'Use the Olson Time Zone Database'.

Regards,
-Patrick

Patrick Happel
05-30-2008, 07:10 AM
Hello Shakila,
Setting RWZone::local() changes a global value, so it will change the default time zone for all Rogue Wave classes in all threads running in the process. The call itself isn't scoped, so the value it changes will remain in effect until the process ends, or RWZone::local() is set to a new value.

Regards,
-Patrick

Shakila
06-04-2008, 02:27 AM
Hi Patrick,

Sorry for the delayed response.
Thanks a lot for your timely replies.

Regards,
Shakila.

Shakila
06-04-2008, 06:58 AM
Hi Patrick,

Sorry for the delayed response.
Thanks a lot for your timely replies.

I need one more clarification.

I have given the following in my program:
"RWZone::local( new RWZoneSimple( RWZone::USMountain, RWZone::NoAm ) );".

Then after my time calculations, how to reset the default time zone for my rest of the program (i.e. to make use of the server's TZ variable)?

I have given "RWZone::os();" in my program but is giving the following error:

Error 221: "trw.C", line 40 # Member 'os' not declared in class RWZone ["/opt/aCC/include/rw/zone.h", line 167].
RWZone::os();
^^^^^^^^^^

It will be very helpful if could help me in resolving this issue.

Thanks in advance,
Shakila.

Patrick Happel
06-05-2008, 09:04 AM
Hi Shakila,

You should be able to just call RWZone::local(RWZone::os()) to set the time zone back to the TZ value. The file '/opt/aCC/include/rw/zone.h' is actually a compiler include file. HP ships a version of the tools library with their compiler, and it looks like you are referencing their zone.h rather than SourcePro's. HP based their version of the tools library on an old version of the .h++ product, which is probably why the RWZone::os() member isn't present.

Make sure that you're referencing SourcePro's zone.h file, and the issue should disappear.

Regards,
-Patrick

Shakila
06-06-2008, 07:29 AM
Thanks a lot Patrick.

I will let you know if I face any issues in resolving this.

Thanks again :-)
Shakila.

dean
06-11-2008, 06:42 AM
Shakila,

It turns out the version of Tools.h++ that ships with the HP compiler is quite an older branch that does not support the RWZone::os() function. The version of the Tools.h++ that is with the aCC compiler is dated 1997 and does not have the complete functionality of the Rogue Wave Tools product. I would recommend that you upgrade to the Rogue Wave version of Tools to get the functionality that you desire with the ability of getting the current system OS Zone.

Let me know if that helps,

Jeremy

Shakila
06-26-2008, 08:44 AM
Hi,

Sorry for the delayed response.
Thanks a lot for your input. I will try to upgrade the roguewave.

Regards,
Shakila.