` Week of year (Kevin Dunsford ) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Par2: Week of year
2001-01-17 -- Kevin Dunsford
 
Note - this does not use Mod because its origins were in Clarion 2003 where % did not always work correctly. It is now for C5. It takes into consisderations the requirements of ISO 2051. Kevin MEMBER('qse.clw') ! This is a MEMBER module MAP INCLUDE('QSE098.INC'),ONCE !Local module prodecure declarations END FWeekNumber PROCEDURE ( Pdate ) ! Declare Procedure loc:Resultstr string(7) ! Returned Result = 'YYYYWWW' Loc:Result Long ! Returned as a long loc:date Long ! Day of year in Clarion standard date form. loc:Year Long ! Long Year that the week belongs to - Passed by Reference loc:aMonday byte(1) ! First day of the first week of year = Monday loc:aThursday byte(4) ! Day number for thursday loc:WeekNo Long ! Week no of loc:Year returned. Note: loc:Year may be ! either the year of the date, the previous year or the next year loc:Week1Date Long ! Calculated date of first week of current year loc:PrevWeek1 Long ! Previous year week 1 date loc:NextWeek1 Long ! Next Year week 1 date CODE ! PROC YEARWEEK ! For a given date - returns the Year and week number of the year ! in a 7 digitstring YYYYWWW all places significant. ! Note, the Year is a 4 digit year that the week is in ! according to ISO 2051 where the first week of the year must contain 4 ! or more days of that year. ! IE: The first thursday in the new year is in the first week of the year. ! The week begins on the monday preceeding that first thursday which ! may be either in the current year or previous year. ! ! NOTE: The year in YYYYWWW may be different from the date year!!! ! Note the week value may be from 1 to 53. ! ie: a week may span the year end and is allocated to which ! ever year 4 or more of its days occur in. ! Refer Croxley Publishing tel: 828-7169. ! --------- If | USE TODAY'S DATE ( Not pdate ) loc:date = Today() else ! DATE PASSED Loc:Date = pDate end ! Pos todays date Loc:Year = Year(loc:Date) ! Calculate Week 1 date for current year loc:Week1Date = Date(1,1,Year(loc:date) ) ! CURRENT YEAR Loop ! FIRST THURSDAY IN YEAR If loc:Week1Date - ( Int(loc:Week1Date/7) * 7) = loc:aThursday then break. loc:Week1Date += 1 end ! First Thursday loc:Week1Date -= 3 ! Previous Monday ! Calculate Week 1 date for Previous year loc:PrevWeek1 = Date(1,1,Year(loc:date)-1 ) Loop ! FIRST THURSDAY IN YEAR If loc:PrevWeek1 - ( Int(loc:PrevWeek1/7) * 7) = loc:aThursday then break. loc:PrevWeek1 += 1 end ! First Thursday loc:PrevWeek1 -= 3 ! Previous Monday ! Calculate Week 1 date for Next year loc:NextWeek1 = Date(1,1,Year(loc:date)+1 ) Loop ! FIRST THURSDAY IN YEAR If loc:NextWeek1 - ( Int(loc:NextWeek1/7) * 7) = loc:aThursday then break. loc:NextWeek1 += 1 end ! First Thursday loc:NextWeek1 -= 3 ! Previous Monday If | DATE IN PREVIOUS YEAR ( loc:date < loc:Week1Date ) loc:Year = Year(loc:date) - 1 loc:WeekNo = INT( (loc:date - loc:PrevWeek1 ) / 7 ) + 1 elsif | DATE IN NEXT YEAR ( loc:date >= loc:NextWeek1 ) loc:Year = Year(loc:date) + 1 loc:WeekNo = INT( (loc:date - loc:NextWeek1 ) / 7 ) + 1 else ! DATE IS IN CURRENT YEAR loc:Year = Year(loc:date) loc:WeekNo = INT( (loc:date - loc:Week1Date ) / 7 ) + 1 end ! Year loc:ResultStr = Format( loc:Year,@n_04 ) & Format(loc:WeekNo,@n_03) If clip(Loc:ResultStr) <> '' then Loc:Result = Loc:ResultStr else Loc:Result = 0. return( loc:Result ) ! ---------------------------------------


Today is November 21, 2024, 7:57 am
This article has been viewed 35211 times.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: