DataCellDateMMsDDsYYYY Class

This class handles conversion to and from the date data type in MM/DD/YYYY format to the schema language date data type in ISO 8601 date format, that is, YYYY-MM-DD. In the MM/DD/YYYY format both the MM and the DD may be either one or two digits in length.

Note: Various library functions are available in Java and C++ that might make the implementation a bit more efficient than the one presented here. However, in the interest of keeping things simple for myself, as I'm implementing in both languages, I've chosen basic algorithms that work equally well in either language. All positions are expressed as offsets from the first character at position zero.

Also, remember that we're only putting enough validation into these routines to avoid nasty runtime exceptions. Schema validation is our primary method for ensuring that we have good dates.

Logic for the DataCellDateMMsDDsYYYY fromXML Method
Arguments:
  None

Returns:
  Error status or throws exception

IF Buffer Length != 10
  Return error
ENDIF
Month <- Cell Buffer characters at offsets 5 and 6
Day <- Cell Buffer characters at offsets 8 and 9
Year <- Cell Buffer characters at offsets 0 through 3
Cell Buffer <- Month + forward slash + Day + forward slash
    + year
Return success

Logic for the DataCellDateMMsDDsYYYY toXML Method
Arguments:
  None

Returns:
  Error status or throws exception

Month State = 0
Day State = 1
Year State = 2
State <- Month
Cell Buffer < trim leading and trailing whitespace from
    Cell Buffer
IF Buffer Length > 10
  Return error
ENDIF
TempChar <- First character in Cell Buffer
DO until end of Cell Buffer
  IF TempChar = Slash
    Increment State
  ELSE
    DO CASE of State
      Month:
        Append TempChar to Month
        BREAK
      Day:
        Append TempChar to Day
        BREAK
      Year:
        Append TempChar to Year
        BREAK
      other:
        Return Error
    ENDDO
  ENDIF
  TempChar <- Next character in Cell Buffer
ENDDO
IF length of Month is 1
  Month <- "0" + Month
ENDIF
If Length of Day is 1
  Day <- "0" + Day
ENDIF
IF (Length of Month != 2) OR (Length of Day != 2) OR
    (Length of Year != 4)
  Return error
ENDIF
Cell Buffer = Year + dash + Month + dash + Day
Return success

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset