def fromString(myDate=None): """ Convert date/time/datetime String back to appropriated objects The format of the string it is assume to be that returned by toString method. See notice on toString method On Error, return None """ if StringTypes.__contains__(type(myDate)): if myDate.find(' ') > 0: dateTimeTuple = myDate.split(' ') dateTuple = dateTimeTuple[0].split('-') try: return (datetime.datetime(year=dateTuple[0], month=dateTuple[1], day=dateTuple[2]) + fromString(dateTimeTuple[1])) # return dt.combine( fromString( dateTimeTuple[0] ), # fromString( dateTimeTuple[1] ) ) except: try: return (datetime.datetime(year=int(dateTuple[0]), month=int(dateTuple[1]), day=int(dateTuple[2])) + fromString(dateTimeTuple[1])) except ValueError: return None # return dt.combine( fromString( dateTimeTuple[0] ), # fromString( dateTimeTuple[1] ) ) elif myDate.find(':') > 0: timeTuple = myDate.replace('.', ':').split(':') try: if len(timeTuple) == 4: return datetime.timedelta(hours=int(timeTuple[0]), minutes=int(timeTuple[1]), seconds=int(timeTuple[2]), microseconds=int(timeTuple[3])) elif len(timeTuple) == 3: try: return datetime.timedelta(hours=int(timeTuple[0]), minutes=int(timeTuple[1]), seconds=int(timeTuple[2]), microseconds=0) except ValueError: return None else: return None except: return None elif myDate.find('-') > 0: dateTuple = myDate.split('-') try: return datetime.date(int(dateTuple[0]), int(dateTuple[1]), int(dateTuple[2])) except: return None return None
def uniquePath(path=None): """ Utility to squeeze the string containing a PATH-like value to leave only unique elements preserving the original order """ if not StringTypes.__contains__(type(path)): return None try: elements = List.uniqueElements(List.fromChar(path, ":")) return ':'.join(elements) except Exception: return None
def uniquePath( path = None ): """ Utility to squeeze the string containing a PATH-like value to leave only unique elements preserving the original order """ if not StringTypes.__contains__( type( path ) ): return None try: elements = List.uniqueElements( List.fromChar( path, ":" ) ) return ':'.join( elements ) except Exception: return None