tCalendar class error

tCalendar class error

Postby TimStone » Wed Jul 07, 2010 5:42 pm

We have discovered the following problem with the tCalendar class.

I am using it within an application. We have the system SET DATE TO AMERICAN which is the format mm/dd/yyyy. You use British dd/mm/yyyy. If we activate the calendar control ( as a resource REDEFINE ) and lookup a date on the loaded calendar, there is no problem. However, if we use the calendar control to reset to the next month, it then sets the system date format to British. Thus, all dates in our program are now displayed as British format.

There are no other functions involved in this process. To test, you could display a date in American format ( mm/dd/yyyy ), then display the calendar, use the control to advance to the next month, exit the calendar, and display the date again. You will see it in British format.

I can fix this within my application by using SET DATE TO AMERICAN after closing the calendar control, but the flaw should be fixed within the class. My fix keeps date displays correct in the program for all other functions and displays.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: tCalendar class error

Postby TimStone » Tue Jul 13, 2010 3:36 pm

This never got a response so I brought it back to the top :D

Has anyone experienced this or is no one else using the calendar control ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: tCalendar class error

Postby James Bott » Tue Jul 13, 2010 4:09 pm

Tim,

Did you search the TCalendar source for "SET DATE" or "set("? One of those must be in there somewhere.

When you find it, you need to save and restore the current date format.

Code: Select all  Expand view
cOldDateFormat := Set( _SET_DATEFORMAT )
SET DATE BRITISH
...
Set( _SET_DATEFORMAT, cOldDateFormat )

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: tCalendar class error

Postby TimStone » Tue Jul 13, 2010 8:04 pm

James,

The class is designed to do all of its work in BRITISH format. On the first call of the class, it saves the program format, then switches to BRITISH. You can't change that because then the class will not work. It also restores the date after the method is called.

I think the problem is that if you call the calendar, it displays and has reset the operational month to BRITISH. If you leave that, you will reset to AMERICAN fine. However, if you change the month from within that calendar control, I think it then resets the default to BRITISH, and the restore then becomes to BRITISH. That is the only thing that makes sense.

When I call the calendar control, I must then reset the main program date format when I leave the function. My point, however, is that a flaw exists in the class that should be fixed. Yes, I have a workaround, but ultimately a broken control will result in other problems.

Also, if I modified the control, I would then need to modify every updated control and I would rather not have that issue to remember.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: tCalendar class error

Postby James Bott » Tue Jul 13, 2010 11:47 pm

Tim,

I meant to find the problem in the control and find a fix. I'm sure Antonio would apply the fix for future releases.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: tCalendar class error

Postby nageswaragunupudi » Wed Jul 14, 2010 7:38 am

I propose the following changes to tcalenda.prg to make the class work independent of the date format set in the application.

In the defines, comment out or remove
Code: Select all  Expand view

//#define DATEFORMAT "dd/mm/yyyy"
 


Include this translate above the CLASS definition.
Code: Select all  Expand view

#xtranslate YMD2D( <y>, <m>, <d> ) => SToD( StrZero( <y>, 4 ) + StrZero( <m>, 2 ) + StrZero( <d>, 2 ) )
 


In the header of the class change these methods as virtual
Code: Select all  Expand view

  METHOD RestoreDateFormat()        VIRTUAL //INLINE Set( _SET_DATEFORMAT, ::cDateFormat )

  METHOD SaveDateFormat()           VIRTUAL //INLINE ::cDateFormat := Set( _SET_DATEFORMAT ), Set( _SET_DATEFORMAT, DATEFORMAT )
 

Or even completely remove these two methods from the entire source wherever they appear.

Replace these methods with the new methods given below
Code: Select all  Expand view

METHOD GetArrayDatesRange() CLASS TCalendar
RETURN { YMD2D( ::pDateRange:nYear1, ::pDateRange:nMonth1, ::pDateRange:nDay1 ), ;
         YMD2D( ::pDateRange:nYear2, ::pDateRange:nMonth2, ::pDateRange:nDay2 )  }

METHOD GetSystemDate() CLASS TCalendar

RETURN YMD2D( ::pSystemDate:nYear, ::pSystemDate:nMonth, ::pSystemDate:nDay )
 


Make this change in the METHOD Notify
for the line:
Code: Select all  Expand view


            dDate := CToD( StrZero( Day( ::dDate ), 2 ) + "/" + StrZero( Month( ::dDate ), 2 ) + "/" + Str( Year( ::dDate ), 4 ) )
 

Substitute
Code: Select all  Expand view

            dDate := ::dDate
 


Now the TCalendar class does not interfere with the DATE FORMAT set in the application program.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 84 guests