Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Y2K fix for Fox 2.x?
Message
 
À
14/11/1998 12:36:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00157526
Message ID:
00157719
Vues:
18
Hi Bill,

>One suggestion for rollover date: Instead of fixing it to one year (1950), or programmatically changing it based on type of date input (birthdates, invoice date, etc.)

Yes, 1950 was just a suggestion of me. The reason I made it a DEFINE is that you know can enter any expression in there, like you did. Or, a function that returns a rollover year based on the current GET, eg. if you have a birthdate and an invoice date on one screen.

>I tested a browse of date fields and it works well. It highlights twice on 02/29/00 and takes a little time to validate, but all other dates are swift to validate.

Unfortunately that's necessary with my solution. It might highlight the field up to three times, depending on several settings.

>Anyone reading this thread must remember (as you point out in your article) that Fox's CTOD() & LUPDATE() aren't 2000 compliant.

These are my replacement function. They aren't the only possible ones. Especially LUPDATE() can also be replaced by ADIR(), I just applied the rollover solution here, as well. BTW, the full source code is available on CompuServe for download.

Christof
   *===============================================
   * Replacement for the built in CTOD() function
   * The original version causes two problems:
   * 1) it always add 19xx with 2-digit years
   * 2) it doesn't recognize "02/29/00".
   * Usage: Add the following line to every single
   * program or screen:
   *  #DEFINE  CTOD   Y2K_CTOD
   *===============================================
   Procedure Y2K_CToD
   Parameter tcDate
   
      *--------------------------------------------
      * get date string. If a short date has been
      * given, and this date equals to "02/29/00",
      * we create a long date string. FoxPro will
      * convert a 4-digit-year properly, even if
      * SET CENTURY is OFF.
      *--------------------------------------------
      Private lcDate, lcCentury
      If Len( tcDate ) <= 8
         lcCentury = Set("Century")
           Set Century Off
         If tcDate == Sys(10,2451604)
            Set Century On
            lcDate = Sys(10,2451604)
         Else
            lcDate = tcdate
         Endif
         Set Century &lcCentury
      Else
         lcDate = tcDate
      Endif

      *--------------------------------------------
      * convert into date format. Evaluate() is
      * necessarty, if #DEFINE CTOD is used and 
      * this function is included into the main
      * program. Strings are not replaced by
      * #DEFINE, so we can nevertheless use CtoD 
      * in a string   
      *--------------------------------------------
      Private ldDate
      ldDate = Evaluate("CToD(lcDate)")

      *--------------------------------------------
      * Handle roll-over with 2-digit years
      *--------------------------------------------
      If Len( tcDate ) <= 8
         If Year( ldDate ) < Y2K_ROLLOVER
            lddate = GoMonth(ldDate,1200)
         Endif
      Endif

   Return ldDate
   
   *===============================================
   * Replacement for the built-in LUPDATE() 
   * The original version causes two problems:
   * 1) it always add 19xx after 2000
   * 2) it doesn't recognize 02/29/2000.
   * Usage: Add the following line to every single
   * program or screen:
   *  #DEFINE  LUPDATE   Y2K_LUPDATE
   *===============================================
   Procedure Y2K_LUpdate
   Parameter tuAlias
   
      *--------------------------------------------
      * check for default work area
      *--------------------------------------------
      If Parameters() == 0
         tuAlias = Select()
      Endif

      *--------------------------------------------
      * table opened in given work area?
      *--------------------------------------------
      If     Type( "tuAlias" ) == "N" ;
         and Empty(Dbf(tuAlias))
         Return {}
      Endif

      *--------------------------------------------
      * get date. Causes error, if tuAlias doesn't
      * exist.
      *--------------------------------------------
      Private ldDate
      ldDate = Evaluate("LUpdate(tuAlias)")
      If Empty(lddate)
         ldDate = Y2K_022900()
      Else
         If Year( ldDate ) < Y2K_ROLLOVER
            lddate = GoMonth(ldDate,1200)
         Endif
      Endif
      
   Return ldDate
--
Christof
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform