def MakeTimecodeString(seconds, fmt='hh:MM:SS.FFF'):
    """
	Convert a number of seconds into a colon-delimited timecode
	string, according to the formatting specified by `fmt`.
	
	NB: `fmt` is not interpreted character-by-character, merely
	checked for *whether or not it contains* certain characters:
	D/d for days, H/h for hours, M/m for minutes, S/s for
	seconds, and F/f for fractions-of-a-second.  Upper-case
	characters indicate mandatory inclusion, whereas lower-case
	letters indicate discretionary inclusion---for example, if
	`fmt` contains H, hours will always get formatted even if
	the number of hours is zero; if `fmt` contains h instead of
	H, hours will get formatted if and only if necessary (i.e.
	if `seconds` >= 3600). If there's no H or h character, you
	will simply see a numbers of minutes larger than 60, when
	appropriate.
	
	The number of occurrences of each character dictates the
	width of the corresponding field, unless otherwise
	constrained.
	
	Higher-order fields override the settings for lower-order
	ones. For example, if hours are getting formatted, minutes
	will always also get formatted, and always with width 2,
	regardless of the presence, absence or count of M and m
	characters.
	"""
    s = '-' if seconds < 0 else ''
    seconds = abs(seconds)
    fmtLower = fmt.lower()
    includeDays = 'D' in fmt or 'd' in fmt and seconds >= 86400
    includeHours = 'H' in fmt or 'h' in fmt and seconds >= 3600 or includeDays
    includeMinutes = 'M' in fmt or 'm' in fmt and seconds >= 60 or includeHours
    dayWidth = fmtLower.count('d')
    hourWidth = 2 if includeDays else fmtLower.count('h')
    minuteWidth = 2 if includeHours else fmtLower.count('m')
    secondWidth = 2 if includeMinutes else fmtLower.count('s')
    decimalPlaces = fmtLower.count('f') if 'F' in fmt or seconds != round(
        seconds) else 0
    if decimalPlaces:
        secondWidth += 1 + decimalPlaces
    seconds = round(seconds * 10 ** (decimalPlaces + 1)
        ) // 10 * 10 ** -decimalPlaces
    if includeDays:
        days = seconds // 86400
        seconds -= days * 86400
        s += '%0{}d:'.format(dayWidth) % days
    if includeHours:
        hours = seconds // 3600
        seconds -= hours * 3600
        s += '%0{}d:'.format(hourWidth) % hours
    if includeMinutes:
        minutes = seconds // 60
        seconds -= minutes * 60
        s += '%0{}d:'.format(minuteWidth) % minutes
    s += '%0{}.{}f'.format(secondWidth, decimalPlaces) % seconds
    return s
