Page 1 of 1

10.3 xBrowse date display error

PostPosted: Tue Mar 30, 2010 11:20 pm
by TimStone
I just recompiled my program with FWH 10.3. Date fields are now displaying the date and then a time, ie. 03/30/2010 00:00:00:00

This is causing problems with the column sizing.

Is there a setting or fix ?

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 6:24 am
by nageswaragunupudi
Immediate workaround is
oCol:cEditPicture := '@D'

The behavior is :
In case of Harbour, if the ValType() is 'T', the value is shown along with time and if the ValType() is 'D', the value is shown as Date without timepart, if oCol:cEditPicture is undefined.

In case of xHarbour, if HB_IsDateTime( <value> ) is true, the value is shown with time part and otherwise date is shown without timepart, if oCol:cEditPicture is undefined.

All xbrowse samples in the samples folder, where the fieldtype is 'D', xbrowse is displaying the values as pure dates only without the timepart.

Example:
Code: Select all  Expand view

#include 'fivewin.ch'
#include 'xbrowse.ch'

function Main()

   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO 'HH:MM:SS'

   xbrowser {{ {^ 2009/10/10}, {^ 2009/10/10 15:15:15} }}

return nil
 

Display:
Image

Will you please inform Harbour or xHarbour version and what data source you are browsing? Is it possible to post a small self contained sample so that a proper fix can be found.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 1:33 pm
by TimStone
FWH 10.3
xHarbour Professional November 2009

The code:
add to oLbxo header "Due Date" data oWrkOrd:duedat ALIGN LEFT SIZE 100

The field is a date field drawn from the database.

This is a new behavior starting with 10.3. Prior to this, xBrowse displayed the date with no problem, so there was apparently a change made on this release.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 1:56 pm
by James Bott
Rao,

I have never seen this caret syntax.

{^ 2009/10/10}

Does this automatically convert the value to a date format?

James

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 2:02 pm
by nageswaragunupudi
James Bott wrote:Rao,

I have never seen this caret syntax.

{^ 2009/10/10}

Does this automatically convert the value to a date format?

James

Yes. This is the new way of writing Date / DateTime constants. Has been there for quite sometime.

Now we can assign date constants to static variables easily.

static tDate := {^ 2000/10/09 15:15:15 }.
This was not possible earlier.
Works both in Harbour and xHarbour.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 2:41 pm
by James Bott
Rao,

Now we can assign date constants to static variables easily.

static tDate := {^ 2000/10/09 15:15:15 }

Hmm, only for statics, not locals?

What does valtype( tDate ) return?

James

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 2:59 pm
by nageswaragunupudi
Hmm, only for statics, not locals?

We can use it anywhere.
Earlier there was no way of initializing static variables with datevalues. Now we can. Thats what I was trying to emphasize.

In Harbour, ValType of DateTime variables is 'T' and pure date ( without time-part ) is 'D'.

In xHarbour ValType of both DateTime and Date varables is 'D'. We can find if a variable has time-part or not by HB_IsDateTime( <dVar> ) --> .t. or .f.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 3:43 pm
by nageswaragunupudi
Mr. Tim

The xHarbour function HB_isDateTime( <var> ) is expected to return .f. when the date variable does not have timepart and .t. when the variable has timepart also.

Several versions back, XBrowse used HB_IsDateTime() to ascertain whether the variable has time-part or not. But in some versions of xHarbour, there was a bug in this function and HB_isDateTime() was returning .t. for all dates, even without time part. At that time XBrowse had a temporary workaround to check if the variable has time-part or not. Now that the bug is resolved in the recent versions of xHarbour, XBrowse again reverted to the old code ( in version 10.3 ) and is now depending on HB_IsDateTime().

Will you please help by checking what is the result of ? HB_IsDateTime( Date() ) in your version of xHarbour?

This will help reinstating the time-part check.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 3:52 pm
by nageswaragunupudi
It may not be out of place to mention a few hints to take the best advantage of XBrowse's built-in capabilities.

If we use the syntax, XBROWSE .... COLUMNS 'col1', 'col2' ... ALIAS <calias> or OBJECT <dataobj>, XBrowse extracts the exact information about the datatype, datalen and datadec from the DbStruct() or oData:aStruct and appropriately decides the correct format, alignment and column width for display. In addition, XBrowse constructs the bOnPostEdit blocks, with shares and locking appropriately/

If we use FIELDS clause or ADD COLUMN syntax, we are preventing XBrowse to learn the information and we naturally take more responsibility to define picture clause, width, bOnPostEdit block, etc.

Using COLUMNS clause not only compacts the code and easier to maintain but also gets a superior performance.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 5:11 pm
by James Bott
Rao,

If we use the syntax, XBROWSE .... COLUMNS 'col1', 'col2' ... ALIAS <calias> or OBJECT <dataobj>,


Can you explain in more detail about using the OBJECT clause, perhaps by providing an example. I am particularly wondering about how you would specify only some fields--not all fields.

James

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 6:48 pm
by TimStone
I am adding PICTURE "@D" to my xbrowses that use a date. When I first started coding with xbrowse it did not automatically format the fields correctly, so I did it this way. Eventually I may be able to revise the code but there is too much to do at this time. The PICTURE statement is a quick fix for now.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 6:52 pm
by TimStone
I'm using Nov 2009 which was the last comprehensive build ... non-beta.

When running your test function, it returns .t.

Tim

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 7:19 pm
by nageswaragunupudi
TimStone wrote:When running your test function, it returns .t.
Tim

This is a bug. It should return .f. .
HB_IsDateTime( DateTime() ) should return .t.
and
HB_IsDateTime( Date() ) should return .f..
This was fixed in subsequent versions of xHarbour and XBrowse 10.3 works same way as earlier with recent versions of xHarbour.

If you include valblank.prg of version 10.2 or earlier from \fwh\source\function\valblank.prg, you should get the earlier behavior.

Probably it may be desirable for FWH to continue the earlier work around for the above bug in xHarbour, because some programmers could still be using older versions of xHarbour commerical.

Also, as I said earlier, if the columns are defined with COLUMNS clause of XBROWSE command, the XBrowse examines the DBF structure and knows that the field is Date and not DateTime. When we use ADD COLUMN syntax, we are denying XBrowse the opportunity to ascertain the real data type of the column.

Re: 10.3 xBrowse date display error

PostPosted: Wed Mar 31, 2010 7:27 pm
by nageswaragunupudi
James Bott wrote:Rao,

If we use the syntax, XBROWSE .... COLUMNS 'col1', 'col2' ... ALIAS <calias> or OBJECT <dataobj>,


Can you explain in more detail about using the OBJECT clause, perhaps by providing an example. I am particularly wondering about how you would specify only some fields--not all fields.

James


\fwh\samples\testxbr3.prg has two samples of using TDataBase object also. This program has samples for RDD, RecordSets, Trees, Arrays, Hashes, etc.

Here is a simplified sample using TDataBase object. Please compile and test this sample as it is and then try changing TDataBase to TData. I expect the same results:
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'ord.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

function Main()

   local oDbf, oDlg, oBrw

   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO 'HH:MM:SS'

   RDDSetDefault( 'DBFCDX' )
   oDbf  := TDataBase():Open( , 'CUSTOMER' )
   oDbf:SetOrder( 'FIRST' )

   DEFINE DIALOG oDlg SIZE 550,400 PIXEL
   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      COLUMNS 'First', 'Married', 'HireDate', 'Salary', 'Age' ;
      OBJECT oDbf ;
      AUTOSORT CELL LINES NOBORDER

   oBrw:Married:SetCheck()
   oBrw:nStretchCol  := 1
   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED
   oDbf:Close()

return nil
 


I think TData class has a DATA aStruct, which is similar to DbStruct. If so, xBrowse ascertains the datatypes from oDbf:aStruct and if not, makes best guess by examining the ValType of the expressions.

If Mr. Tim is using TData class, he may try this sample with TData class. This example shows HireDate as Date but not as DateTime, because the fieldtype is 'D' and not 'T' or '@'.

Image

Re: 10.3 xBrowse date display error

PostPosted: Fri Apr 02, 2010 3:09 pm
by nageswaragunupudi
Mr TimStone

It is desirable to modify FWH library to retain compatibility with the xHb version (Nov 2009) than your modifying your source code.

Can you help by testing this small sample with your version of xHb ?
Code: Select all  Expand view

#include 'fivewin.ch'
#include 'xbrowse.ch'

function Main()

   local d

   d  := Date()
   ? HasTimePart( d )  // should return .f.
   d  := DateTime()
   ? HasTimePart( d )  // should return .t.

return nil


function HasTimePart( d )
return ( d - Int( d ) ) > 0