Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Opposite of week
Message
 
 
À
28/02/2001 08:14:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00480131
Message ID:
00480560
Vues:
11
Hi Daniel,

Just curious, how did you format this code into HTML color-code? It was formatted incorrectly. You probably used outdated version of Mike's code.

>Michelle:
>
>This is a generic version of the reverse of Week. To get the 5th Tuesday of year 2000 and assuming the first week of the year contains January 1st and the first day of the week is a Monday, the call GetDate(2000, 5, 3, 1, 2).
>
>I perform a fair number of tests but I did not test everything so there miight be a bug left in there...
>
>DDaniel
>
>
>
>*==============================================================================
>*                                    GetDate
>*                                    -------
>*
>*  Purpose.......: Returns the date that falls on the specified day, week, 
>*                  year combination.
>*  Author........: Daniel Rouleau - Metro Information Services
>*  Last Revision.: 2001-02-27
>*
>*  Syntax........: GetDate( tnYear,           ;
>*                           tnWeek,           ;
>*                           tnDayOfWeek,      ;
>*                           [tnFirstWeek],    ;
>*                           tnFirstDayOfWeek) ;
>*                         )
>*  Returns.......: Date
>*  Arguments.....: tnYear
>*                    Specifies the year of the date to return.
>*
>*                  tnWeek 
>*                    Specifies the week number of the date to return.
>*
>*                  tnDayOfdWeek
>*                    Specifies the day of the week of the date to return.
>*
>*                  tnFirstWeek 
>*                    Specifies the requirements for the first week of the year.
>*                    Default is 0.  See Week() in VFP 6.0 Help for details.
>*
>*                  tnFirstDayOfWeek
>*                    Specifies the first day of the week.   Default is 0.
>*                    See Week() in VFP 6.0 Help for details.
>*
>*  Remarks.......:
>*==============================================================================
>Lparameters tnYear, tnWeek, tnDayOfWeek, tnFirstWeek, tnFirstDayOfWeek
>
>Local ldRetVal
>Local lnFirstDay
>Local ldFirstDayOfYear
>Local lnFirstWeek
>Local ldJanuary01
>Local lnJanuary01Dow
>Local lcCenturry
>Local lcDate
>Local lnStrictDate
>
>*-----------------------
>*  Validate parameters. 
>*-----------------------
>If Vartype(tnYear)  'N' Or Int(tnYear)  tnYear Or Not Between(tnYear, 1, 9999) Or ;
>   Vartype(tnWeek)  'N' Or Int(tnWeek)  tnWeek Or Not Between(tnWeek, 1, 53) Or   ;
>   Vartype(tnDayOfWeek)  'N' Or Not Inlist(tnDayOfWeek, 1, 2, 3, 4, 5, 6, 7) Then
>
>   *-- Return an empty date as we have an invalid combination.
>   Return {}
>EndIf
>
>If Vartype(tnFirstWeek) = 'N' And Inlist(tnFirstWeek, 1, 2, 3) Then
>   lnFirstWeek = tnFirstWeek
>Else
>   lnFirstWeek = 0
>EndIf
>
>If Vartype(tnFirstDayOfWeek) = 'N' And Inlist(tnFirstDayOfWeek, 1, 2, 3, 4, 5, 6, 7) Then
>   lnFirstDayOfWeek = tnFirstDayOfWeek
>Else
>   lnFirstDayOfWeek = 0
>EndIf
>
>If lnFirstWeek = 0 Then
>   lnFirstWeek = Set('FWeek')
>EndIf
>
>If lnFirstDayOfWeek = 0 Then
>   lnFirstDayOfWeek = Set('FDow')
>EndIf
>
>*-------------------
>*  Change settings.
>*-------------------
>lnStrictdate = Set('Strictdate')
>lcCentury = Set('Century')
>lcDate = Set('Date')
>
>Set Strictdate to 0
>Set Century On
>Set Date to Ansi
>
>*-----------
>*  Process.
>*-----------
>ldJanuary01 = CTOD(Right('0000' + Ltrim(Str(tnYear, 4)),4) + '.01.01')
>lnJanuary01Week = Week(ldJanuary01, lnFirstWeek, lnFirstDayOfWeek)
>lnJanuary01Dow = Dow(ldJanuary01)
>
>Do Case
>Case tnFirstWeek = 1
>   ldFirstDayOfYear = ldJanuary01 - (lnJanuary01Dow - lnFirstDayOfWeek)
>
>Case tnFirstWeek = 2
>   If lnJanuary01Dow - lnFirstDayOfWeek >= 4 Then
>      ldFirstDayOfYear = ldJanuary01 + (7 + lnFirstDayOfWeek - lnJanuary01Dow)
>   Else
>      ldFirstDayOfYear = ldJanuary01 + (lnFirstDayOfWeek - lnJanuary01Dow)
>   Endif
>
>Case tnFirstWeek = 3
>   If lnFirstDayOfWeek >= lnJanuary01Dow Then
>      ldFirstDayOfYear = ldJanuary01 + (lnFirstDayOfWeek - lnJanuary01Dow)
>   Else
>      ldFirstDayOfYear = ldJanuary01 + (7 + lnFirstDayOfWeek - lnJanuary01Dow)
>   EndIf
>EndCase
>
>If tnDayOfWeek >= lnFirstDayOfWeek Then
>   ldRetVal = ldFirstDayOfYear + (7 * (tnWeek-1)) + (tnDayOfWeek - lnFirstDayOfWeek)
>Else
>   ldRetVal = ldFirstDayOfYear + (7 * (tnWeek)) + (tnDayOfWeek - lnFirstDayOfWeek)
>EndIf
>
>Clear
>? ldJanuary01
>? lnJanuary01Dow
>? ldFirstDayOfYear
>? ldRetVal
>
>*-------------------
>*  Rstore settings.
>*-------------------
>Set Date To &lcDate
>Set Century &lcCentury
>Set Strictdate to &lnStrictDate
>
>
>Return ( ldRetVal )
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform