Page 1 of 1

Calendar International Date Question

Posted: Thu Dec 03, 2020 8:28 am
by AUGE_OHR
hi,

i´m working on my Outlook Calendar Clone using HMG and have some Question how it is used in "your" Country

a.) first Day of Week :
in Germany it is Monday.
will harbour "set" right Day for DOW() :?:

b.) Week of Year :

Code: Select all

FUNCTION XF_WeekofYear( dDatum )
LOCAL nDay, nWoche
   nDay := DOW( CTOD( "31.12." + STR( YEAR( dDatum - 7 ), 4 ) ) )
   nDay := IF( nDay = 1, 7, nDay - 1 )
   nWoche := ROUND( ( dDatum - CTOD( "1.1." + STR( YEAR( dDatum ), 4 ) ) ;
                    + 8 - IF( DOW( dDatum ) = 1, 7, DOW( dDatum ) - 1 ) ) / 7, 0 )
   nWoche := IF( nWoche < 53, nWoche, IF( nDay > 3, nWoche, 1 ) )
   // if 4 Days or more in new Year -> 1st Week
   nWoche := INT( IF( nWoche = 0, IF( nDay > 4, 52, 53 ), nWoche ) )
RETURN ( nWoche )
c. ) how many Weeks in a Month :

Code: Select all

FUNCTION XF_WeeksinMonth( dDatum )
LOCAL nYear,nMonth,dFirst,dLast
LOCAL nDiff  := 0
LOCAL nWeeks := 5
   dFirst := STOD( STRZERO( nYear, 4 ) + STRZERO( nMonth, 2 ) + "01" )
   dLast := STOD( STRZERO( nYear, 4 ) + STRZERO( nMonth + 1, 2 ) + "01" )
   nDiff := dLast - dFirst
   IF ( DOW( dFirst ) > 6 .OR. DOW( dFirst ) = 1 ) .AND. nDiff > 28
      nWeeks := 6
   ENDIF
RETURN nWeeks
all based on German Calendar.
thx for help

Re: Calendar International Date Question

Posted: Thu Dec 03, 2020 8:34 am
by serge_girard
Jimmy,

See this:

Code: Select all

hb_Week( <dDate>, [@<nYear>], [@<nDayOfWeek>] ) ➡️ nWeek

https://github.com/Petewg/harbour-core/wiki/Date-Time

Maybe that can help!

Serge

Re: Calendar International Date Question

Posted: Thu Dec 03, 2020 8:36 am
by serge_girard
It is indeed that dBase takes the sunday as first day. Our week starts monday and the last day (sunday) is our rest-day....
Strange thought... I always had to "correct" daynumber (nDay := IF( nDay = 1, 7, nDay - 1 ))

Serge