FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour tCalendar class error
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
tCalendar class error
Posted: Wed Jul 07, 2010 05: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
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: tCalendar class error
Posted: Tue Jul 13, 2010 03: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: tCalendar class error
Posted: Tue Jul 13, 2010 04: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 (fw): Select all Collapse
cOldDateFormat := Set( _SET_DATEFORMAT ) 
SET DATE BRITISH
...
Set( _SET_DATEFORMAT, cOldDateFormat )

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: tCalendar class error
Posted: Tue Jul 13, 2010 08: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: tCalendar class error
Posted: 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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: tCalendar class error
Posted: Wed Jul 14, 2010 07: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 (fw): Select all Collapse
//#define DATEFORMAT "dd/mm/yyyy"


Include this translate above the CLASS definition.
Code (fw): Select all Collapse
#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 (fw): Select all Collapse
  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 (fw): Select all Collapse
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 (fw): Select all Collapse
            dDate := CToD( StrZero( Day( ::dDate ), 2 ) + "/" + StrZero( Month( ::dDate ), 2 ) + "/" + Str( Year( ::dDate ), 4 ) )

Substitute
Code (fw): Select all Collapse
            dDate := ::dDate


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



G. N. Rao.

Hyderabad, India

Continue the discussion