Example CHGDATE.PRT
; CHGDATE
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Change each date from the format 'dd/mm/yy' to the format 'dd mmm yyyy'; 
; the date must use at least one of the separators in Seps (which must also include ' ').
; All the tokens are used just once; no library function on dates is exploited.
; See chgdat2.prt for a similar (but faster) algorithm.

; Initialize variables
FUNCTION ONSTART()

  IF STREQ(ARGV(3), "..")
    CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " source destination"
    CONSOLELN "Purpose: change dates from numeric to alphanumeric"
    ABORT 0
  FI

  _Seps = " ,;:.()[]<>-{}"
  _MONTHS = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"

  ; EPOCH is used to determine if year is 20xx or 19xx;
  ; values below EPOCH are considered above 2000,
  ; values above are considered before 2000.
  _EPOCH = 70
RETURN

; Find out the number of tokens in line
NTok = NUMTOKEN(L, Seps)

CurTok = 1

NewL = STRDUP(L)

; For each token...
WHILE LE(CurTok, NTok)

  PL = TOKEN(L, CurTok, Seps)

  ; Is token a date?
  IF REXMATCH(PL, "^[0-3][0-9]/[0-1][0-9]/[0-9][0-9]$")

    ; Faster test, using IMATCH (no check on numbers):
    ; IF IMATCH(PL, "??/??/??")

    DD = LEFT(PL, 2)
    MM = SUBSTR(PL, 4, 2)
    YY = RIGHT(PL, 2)

    ; Check that day and month are within the allowed interval
    ; (does not check that the month can actually have the
    ; specified number of days)
    IF ValidMMDD(DD, MM)

      ; Extract from MONTHS the string corresponding to the month
      MMS = " " TOKEN(MONTHS, MM, " ") " "

      ; Add due digits for year
      IF GT(YY, EPOCH)
        YY = "19" YY
      ELSE
        YY = "20" YY
      FI

      ; Store new date to NPL
      NPL = DD MMS YY

      ; Find where the date is in NewL
      P = POSTOKEN(NewL, CurTok, Seps)

      ; Replace date in NewL
      NewL = INSERT(DELETE(NewL, P, 8), P, NPL)

      ; We have added two tokens: update CurTok and NTok
      ADD(@CurTok, 2)
      NTok = ADD(CurTok, 2)
    FI
  FI

  INC(@CurTok)
LOOP

PRINTLN NewL


FUNCTION ValidMMDD(dd, mm)

  IF AND(GE(dd, 1), LE(dd, 31))
    IF AND(GE(mm, 1), LE(mm, 12))
      RETURN 1
    FI
  FI
RETURN 0
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell