From 61a842ca5950535f00a12b6c7e78610ad3a4f1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Fri, 16 Dec 2016 11:05:10 +0100 Subject: [PATCH] 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 author wanted to reach but now WOY() be default returns ISO 8601 week number and simple week number if 2-nd parameter is .F. --- ChangeLog.txt | 6 ++++++ contrib/hbmisc/dates.c | 34 +++++++++++----------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8232dd1422..f27345b305 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,12 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +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 + author wanted to reach but now WOY() be default returns ISO 8601 + week number and simple week number if 2-nd parameter is .F. + 2016-12-15 12:51 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/harbour.hbx * src/harbour.def diff --git a/contrib/hbmisc/dates.c b/contrib/hbmisc/dates.c index 44673d35f2..37ab03bdb9 100644 --- a/contrib/hbmisc/dates.c +++ b/contrib/hbmisc/dates.c @@ -95,22 +95,19 @@ static int hb_doy( int iYear, int iMonth, int iDay ) return iDoy + iDay; } -static int hb_woy( int iYear, int iMonth, int iDay, HB_BOOL bISO ) +static int hb_woy( long lDate, HB_BOOL fISO ) { - int iWeek, n; + int iYear, iMonth, iDay; - HB_TRACE( HB_TR_DEBUG, ( "hb_woy(%d, %d, %d, %d)", iYear, iMonth, iDay, ( int ) bISO ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_woy(%ld, %d)", lDate, ( int ) fISO ) ); - iDay = hb_doy( iYear, iMonth, iDay ); - n = ( ( ( 1 - ( bISO ? 1 : 0 ) ) % 7 ) ) - 1; - iDay += ( n > 0 ) ? 1 : 0; - iWeek = iDay / 7; - if( bISO ) - iWeek += ( n < 4 ) ? 1 : 0; - else - ++iWeek; + hb_dateDecode( lDate, &iYear, &iMonth, &iDay ); - return iWeek; + if( fISO ) + hb_dateDecode( lDate + 3 - ( hb_dateDOW( iYear, iMonth, iDay ) + 5 ) % 7, + &iYear, &iMonth, &iDay ); + + return ( hb_doy( iYear, iMonth, iDay ) - 1 ) / 7 + 1; } HB_FUNC( AMONTHS ) @@ -165,19 +162,10 @@ HB_FUNC( HBMISC_DAYSINMONTH ) hb_retni( 0 ); } -/* Return the nWeek of the year (1 - 52, 0 - 52 if ISO) */ - HB_FUNC( WOY ) { PHB_ITEM pDate = hb_param( 1, HB_IT_DATETIME ); - if( pDate ) - { - int iYear, iMonth, iDay; - - hb_dateDecode( hb_itemGetDL( pDate ), &iYear, &iMonth, &iDay ); - hb_retni( hb_woy( iYear, iMonth, iDay, hb_parldef( 2, HB_TRUE ) ) ); - } - else - hb_retni( 0 ); + hb_retni( pDate == NULL ? 0 : + hb_woy( hb_itemGetDL( pDate ), hb_parldef( 2, HB_TRUE ) ) ); }