'===========================================================================
' Subject: DISPLAY DATES FOR PB/PBCC          Date: 09-17-98 (15:03)       
'  Author: Don Schullian                      Code: PB                     
'  Origin: d83@ath.forthnet.gr              Packet: DATETIME.ABC
'===========================================================================
$if 0
  Hi all you non-Americans and other individuals that need to display
  the date in any one of the myriad formats found around the world;
  here's a little idea I came up with that you may find interesting.

  By calling DateSetup you load the individual members of the TYPE with
  the info to 'build' a date in the required format very quickly and with
  a minimum of code.

  In the function fYMD2Date you'll find a "$if". It is now set to work in
  PB v3.5 so to get it over to PBcc just change the 1 to a ZERO, the
  DIM tDate to GLOBAL tDate, VARPTR32 to VARPTR, and you're all set.

  In my business programs I convert the dates to WORDs (or LONGs). The
  system uses day numbers; 01-01-1872 is day #1 and day #65536 is in the
  year 2050. This provides QUICK computations and tight storage. It also
  means that the dates can be unpacked into any/all formats for use by
  humans, hence this bit of an idea I offer to you today. Hope it will
  come in handy for you.

  C'ya,

  ____    _    ____      ____  _____
 |  _ \  / \  / ___) __ | ___)(_   _)  Don Schullian
 | |_)  / _ \ \____\/  \|  _)   | |     d83@ath.forthnet.gr
 |____//_/ \_\(____/\__/|_|     |_|      www.DASoftVSS.com
 ___________________________________      www.basicguru.com
     Vertical Software Solutions
$endif

TYPE DateDataTYPE
  Today     AS STRING * 10
  Mask      AS STRING * 10
  Seperator AS BYTE
  Format    AS BYTE
  Y_ptr     AS STRING PTR * 4
  M_ptr     AS STRING PTR * 2
  D_ptr     AS STRING PTR * 2
END TYPE

  DIM tDate AS SHARED DateDataType
' GLOBAL tDate AS DateDataTYPE             ' need this for PBcc

CLS
DateSetup 0, 47 : PRINT fYMD2Date(1999,1,20)
DateSetup 1, 45 : PRINT fYMD2Date(1999,1,20)
DateSetup 2, 46 : PRINT fYMD2Date(1999,1,20)

SUB DateSetup (BYVAL Format AS BYTE, BYVAL Seperator AS BYTE)

  IF Seperator = 0 THEN
      tDate.Seperator = 45
    ELSE
      tDate.Seperator = Seperator
  END IF
  tDate.Format = ( Format AND 3 )
  tDate.Mask   = ""

  IF tDate.Format < 2 THEN
      ASC(tDate.Mask,3) = tDate.Seperator
      ASC(tDate.Mask,6) = tDate.Seperator
      tDate.M_ptr       = VARPTR32(tDate.Mask)         ' change this for PBcc
      tDate.Y_ptr       = tDate.M_ptr + 6
      tDate.D_ptr       = tDate.M_ptr + 3
      IF tDate.Format = 1 THEN SWAP tDate.M_ptr, tDate.D_ptr
    ELSE
      ASC(tDate.Mask,5) = tDate.Seperator
      ASC(tDate.Mask,8) = tDate.Seperator
      tDate.Y_ptr       = VARPTR32(tDate.Mask)         ' change this for PBcc
      tDate.M_ptr       = tDate.Y_ptr + 5
      tDate.D_ptr       = tDate.Y_ptr + 8
  END IF

  tDate.@Y_ptr = MID$(DATE$,7)                     ' set tDate.Today
  tDate.@M_ptr =      DATE$
  tDate.@D_ptr = MID$(DATE$,4)
  tDate.Today  = tDate.Mask

END SUB

FUNCTION fYMD2Date (BYVAL Year  AS LONG, _
                    BYVAL Month AS LONG, _
                    BYVAL Day   AS LONG  ) AS STRING

$if 1                                        ' PowerBASIC v3.x
  DIM Dyte AS LOCAL STRING
  tDate.@Y_ptr = USING$("####", Year  )
  tDate.@M_ptr = USING$("##"  , Month )
  tDate.@D_ptr = USING$("##"  , Day   )
  Dyte = tDate.Mask
  REPLACE " " WITH "0" IN Dyte
  FUNCTION = Dyte
$else                                        ' PowerBASIC cc
  tDate.@Y_ptr = FORMAT$(Year , "####" )
  tDate.@M_ptr = FORMAT$(Month, "00"   )
  tDate.@D_ptr = FORMAT$(Day  , "00"   )
  FUNCTION = tDate.Mask
$endif

END FUNCTION
