2017-02-08 19:36 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* contrib/gtqtc/gtqtc1.cpp
    ! fixed clipboard selection with shift + left mouse button to not report
      mouse events during selection

  * include/hbdate.h
  * src/common/hbdate.c
    + added support for ISO 8601 week dates (YYYY-Www-D) in timestamp
      literals
    + added support for ISO 8601 ordinal dates (YYYY-DDD) in timestamp
      literals
    + added new C functions:
         HB_BOOL hb_dateDecWeek( long lJulian, int * piYear,
                                 int * piWeek, int * piDay );
         long hb_dateEncWeek( int iYear, int iWeek, int iDay );
      to decode/encode ISO 8601 week dates

  * src/rtl/dateshb.c
    + added new PRG function get week number and other parts ISO 8601
      week date:
         hb_Week( <dDate>, [@<nYear>], [@<nDayOfWeek>] ) -> <nWeek>

  * include/harbour.hbx
  * src/harbour.def
    * updated for new functions
This commit is contained in:
Przemysław Czerpak
2017-02-08 19:36:46 +01:00
parent 61a842ca59
commit 459cd1a2c5
7 changed files with 163 additions and 30 deletions

View File

@@ -10,6 +10,32 @@
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
*/
2017-02-08 19:36 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* contrib/gtqtc/gtqtc1.cpp
! fixed clipboard selection with shift + left mouse button to not report
mouse events during selection
* include/hbdate.h
* src/common/hbdate.c
+ added support for ISO 8601 week dates (YYYY-Www-D) in timestamp
literals
+ added support for ISO 8601 ordinal dates (YYYY-DDD) in timestamp
literals
+ added new C functions:
HB_BOOL hb_dateDecWeek( long lJulian, int * piYear,
int * piWeek, int * piDay );
long hb_dateEncWeek( int iYear, int iWeek, int iDay );
to decode/encode ISO 8601 week dates
* src/rtl/dateshb.c
+ added new PRG function get week number and other parts ISO 8601
week date:
hb_Week( <dDate>, [@<nYear>], [@<nDayOfWeek>] ) -> <nWeek>
* include/harbour.hbx
* src/harbour.def
* updated for new functions
2016-12-16 11:05 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* contrib/hbmisc/dates.c
! fixed WOY() to return some reasonable results. I have no idea what

View File

@@ -3016,27 +3016,16 @@ void QTConsole::focusOutEvent( QFocusEvent * evt )
void QTConsole::mouseMoveEvent( QMouseEvent * evt )
{
if( pQTC->fSelectCopy &&
( evt->buttons() & Qt::LeftButton ) &&
( evt->modifiers() & Qt::ShiftModifier ) )
if( pQTC->fSelectCopy && selectMode )
{
if( ! selectMode )
{
selectMode = true;
selectRect.setCoords( evt->x(), evt->y(), evt->x(), evt->y() );
update( hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) ) );
}
else
{
QRect rSel1 = hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) );
selectRect.setBottomRight( evt->pos() );
QRect rSel2 = hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) );
if( rSel1 != rSel2 )
update( QRegion( rSel1 ).xored( QRegion( rSel2 ) ) );
}
QRect rSel1 = hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) );
selectRect.setBottomRight( evt->pos() );
QRect rSel2 = hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) );
if( rSel1 != rSel2 )
update( QRegion( rSel1 ).xored( QRegion( rSel2 ) ) );
}
hb_gt_qtc_setMouseKey( pQTC, evt->x(), evt->y(), 0, evt->modifiers() );
else
hb_gt_qtc_setMouseKey( pQTC, evt->x(), evt->y(), 0, evt->modifiers() );
}
void QTConsole::wheelEvent( QWheelEvent * evt )
@@ -3101,6 +3090,13 @@ void QTConsole::mousePressEvent( QMouseEvent * evt )
switch( evt->button() )
{
case Qt::LeftButton:
if( ! selectMode && ( evt->modifiers() & Qt::ShiftModifier ) )
{
selectMode = true;
selectRect.setCoords( evt->x(), evt->y(), evt->x(), evt->y() );
update( hb_gt_qtc_unmapRect( pQTC, hb_gt_qtc_mapRect( pQTC, image, selectRect ) ) );
return;
}
iKey = K_LBUTTONDOWN;
break;
@@ -3127,6 +3123,11 @@ void QTConsole::mouseReleaseEvent( QMouseEvent * evt )
switch( evt->button() )
{
case Qt::LeftButton:
if( selectMode )
{
copySelection();
return;
}
iKey = K_LBUTTONUP;
break;

View File

@@ -961,6 +961,7 @@ DYNAMIC hb_vfUnlock
DYNAMIC hb_vfWrite
DYNAMIC hb_vfWriteAt
DYNAMIC hb_WAEval
DYNAMIC hb_Week
DYNAMIC hb_WildMatch
DYNAMIC hb_WildMatchI
DYNAMIC hb_ZCompress

View File

@@ -70,6 +70,8 @@ extern HB_EXPORT char * hb_dateDecStr( char * szDate, long lJulian );
extern HB_EXPORT long hb_dateEncStr( const char * szDate );
extern HB_EXPORT int hb_dateDOW( int iYear, int iMonth, int iDay );
extern HB_EXPORT int hb_dateJulianDOW( long lJulian );
extern HB_EXPORT HB_BOOL hb_dateDecWeek( long lJulian, int * piYear, int * piWeek, int * piDay );
extern HB_EXPORT long hb_dateEncWeek( int iYear, int iWeek, int iDay );
/* RTL functions */
extern HB_EXPORT const char * hb_dateCMonth( int iMonth );

View File

@@ -370,6 +370,42 @@ int hb_dateJulianDOW( long lJulian )
return 0;
}
HB_BOOL hb_dateDecWeek( long lJulian, int * piYear, int * piWeek, int * piDay )
{
HB_TRACE( HB_TR_DEBUG, ( "hb_dateDecWeek(%ld,%p,%p,%p)", lJulian, piYear, piWeek, piDay ) );
if( lJulian >= HB_STR_DATE_BASE )
{
int iMonth, iDay;
*piDay = ( int ) ( lJulian % 7 ) + 1;
lJulian += 4 - *piDay;
hb_dateDecode( lJulian, piYear, &iMonth, &iDay );
*piWeek = ( lJulian - hb_dateEncode( *piYear, 1, 1 ) ) / 7 + 1;
return HB_TRUE;
}
*piYear = *piWeek = *piDay = 0;
return HB_FALSE;
}
long hb_dateEncWeek( int iYear, int iWeek, int iDay )
{
long lDate = 0;
HB_TRACE( HB_TR_DEBUG, ( "hb_dateEncWeek(%d,%d,%d)", iYear, iWeek, iDay ) );
if( iWeek > 0 && iWeek <= 53 && iDay > 0 && iDay <= 7 )
{
lDate = hb_dateEncode( iYear, 1, 1 );
lDate += ( iWeek - 1 ) * 7 + iDay - ( lDate + 3 ) % 7 + 2;
}
return lDate;
}
int hb_dateDOW( int iYear, int iMonth, int iDay )
{
HB_TRACE( HB_TR_DEBUG, ( "hb_dateDOW(%d, %d, %d)", iYear, iMonth, iDay ) );
@@ -704,26 +740,72 @@ HB_BOOL hb_timeStampStrGet( const char * szDateTime,
++szDateTime;
if( HB_ISDIGIT( szDateTime[ 0 ] ) && HB_ISDIGIT( szDateTime[ 1 ] ) &&
HB_ISDIGIT( szDateTime[ 2 ] ) && HB_ISDIGIT( szDateTime[ 3 ] ) &&
( szDateTime[ 4 ] == '-' || szDateTime[ 4 ] == '/' || szDateTime[ 4 ] == '.' ) &&
HB_ISDIGIT( szDateTime[ 5 ] ) && HB_ISDIGIT( szDateTime[ 6 ] ) &&
szDateTime[ 7 ] == szDateTime[ 4 ] &&
HB_ISDIGIT( szDateTime[ 9 ] ) && HB_ISDIGIT( szDateTime[ 9 ] ) &&
! HB_ISDIGIT( szDateTime[ 10 ] ) )
( szDateTime[ 4 ] == '-' || szDateTime[ 4 ] == '/' || szDateTime[ 4 ] == '.' ) )
{
iYear = ( ( ( int ) ( szDateTime[ 0 ] - '0' ) * 10 +
( int ) ( szDateTime[ 1 ] - '0' ) ) * 10 +
( int ) ( szDateTime[ 2 ] - '0' ) ) * 10 +
( int ) ( szDateTime[ 3 ] - '0' );
iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' );
iDay = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' );
if( hb_dateEncode( iYear, iMonth, iDay ) != 0 ||
( iYear == 0 && iMonth == 0 && iDay == 0 ) )
/* ISO 8601 Calendar dates: YYYY-MM-DD */
if( HB_ISDIGIT( szDateTime[ 5 ] ) && HB_ISDIGIT( szDateTime[ 6 ] ) &&
szDateTime[ 7 ] == szDateTime[ 4 ] &&
HB_ISDIGIT( szDateTime[ 8 ] ) && HB_ISDIGIT( szDateTime[ 9 ] ) &&
! HB_ISDIGIT( szDateTime[ 10 ] ) )
{
iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' );
iDay = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' );
if( hb_dateEncode( iYear, iMonth, iDay ) != 0 ||
( iYear == 0 && iMonth == 0 && iDay == 0 ) )
{
szDateTime += 10;
fValid = HB_TRUE;
}
}
/* ISO 8601 Week dates: YYYY-Www-D */
else if( ( szDateTime[ 5 ] == 'W' || szDateTime[ 5 ] == 'w' ) &&
HB_ISDIGIT( szDateTime[ 6 ] ) && HB_ISDIGIT( szDateTime[ 7 ] ) &&
szDateTime[ 8 ] == szDateTime[ 4 ] &&
HB_ISDIGIT( szDateTime[ 9 ] ) && ! HB_ISDIGIT( szDateTime[ 10 ] ) )
{
long lDate = hb_dateEncWeek( iYear,
( szDateTime[ 6 ] - '0' ) * 10 + ( szDateTime[ 7 ] - '0' ),
szDateTime[ 9 ] - '0' );
if( lDate )
{
hb_dateDecode( lDate, &iYear, &iMonth, &iDay );
szDateTime += 10;
fValid = HB_TRUE;
}
}
/* ISO 8601 Ordinal dates: YYYY-DDD */
else if( szDateTime[ 4 ] == '-' && HB_ISDIGIT( szDateTime[ 5 ] ) &&
HB_ISDIGIT( szDateTime[ 6 ] ) && HB_ISDIGIT( szDateTime[ 7 ] ) &&
! HB_ISDIGIT( szDateTime[ 8 ] ) )
{
iDay = ( ( int ) ( szDateTime[ 5 ] - '0' ) * 10 +
( int ) ( szDateTime[ 6 ] - '0' ) ) * 10 +
( int ) ( szDateTime[ 7 ] - '0' );
if( iDay > 0 && ( iDay <= 365 || ( iDay == 366 &&
iYear % 4 == 0 && ( iYear % 100 != 0 || iYear % 400 == 0 ) ) ) )
{
long lDate = hb_dateEncode( iYear, 1, 1 );
if( lDate )
{
hb_dateDecode( lDate + iDay - 1, &iYear, &iMonth, &iDay );
szDateTime += 8;
fValid = HB_TRUE;
}
}
}
if( fValid )
{
szDateTime += 10;
if( *szDateTime == 'T' || *szDateTime == 't' )
{
if( HB_ISDIGIT( szDateTime[ 1 ] ) )
++szDateTime;
fValid = HB_FALSE;
}
else
{
@@ -733,7 +815,6 @@ HB_BOOL hb_timeStampStrGet( const char * szDateTime,
++szDateTime;
if( *szDateTime == '\0' )
szDateTime = NULL;
fValid = HB_TRUE;
}
}
else

View File

@@ -1146,6 +1146,7 @@ HB_FUN_HB_VFUNLOCK
HB_FUN_HB_VFWRITE
HB_FUN_HB_VFWRITEAT
HB_FUN_HB_WAEVAL
HB_FUN_HB_WEEK
HB_FUN_HB_WILDMATCH
HB_FUN_HB_WILDMATCHI
HB_FUN_HB_ZCOMPRESS
@@ -2316,8 +2317,10 @@ hb_dateCDOW
hb_dateCMonth
hb_dateDOW
hb_dateDecStr
hb_dateDecWeek
hb_dateDecode
hb_dateEncStr
hb_dateEncWeek
hb_dateEncode
hb_dateFormat
hb_dateJulianDOW

View File

@@ -584,6 +584,25 @@ HB_FUNC( HB_STRTOTS )
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
/* get week number and other parts ISO 8601 week date:
hb_Week( <dDate>, [@<nYear>], [@<nDayOfWeek>] ) -> <nWeek> */
HB_FUNC( HB_WEEK )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME );
if( pDate )
{
int iYear, iWeek, iDay;
hb_dateDecWeek( hb_itemGetDL( pDate ), &iYear, &iWeek, &iDay );
hb_storni( iYear, 2 );
hb_storni( iDay, 3 );
hb_retni( iWeek );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( HB_UTCOFFSET )
{
if( HB_ISDATETIME( 1 ) )