Calendar International Date Question

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Calendar International Date Question

Post 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
have fun
Jimmy
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calendar International Date Question

Post 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
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Calendar International Date Question

Post 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
There's nothing you can do that can't be done...
Post Reply