def dec_datestamp(datestamp):
    """Given a 5 character datestamp made by makestamp, it returns it as the tuple :
    (daynumber, timestamp).
    daynumber and timestamp can either be None *or*
    daynumber is an integer between 1 and 16777215
    timestamp is  (HOUR, MINUTES)

    The function 'counttodate' in dateutils will turn a daynumber back into a date."""
    daynumber = datestamp[:3]
    timechars = datestamp[3:]
    daynumber = ord(daynumber[0])*65536 + ord(daynumber[1])*256 + ord(daynumber[2])
    if daynumber == 0: daynumber = None
    if ord(timechars[0]) == 255:
        timestamp = None
    else:
        timestamp = (ord(timechars[0]), ord(timechars[1]))
    return daynumber, timestamp