from .dates_add_days import days_from_civil, parse_iso_date def lot_number(production_date: str, line: int, sequence: int) -> str: """Lot code YYDDD-LL-SSS: two-digit year, day of the year, line, sequence. The day of the year counts from the epoch-day kernel in dates.add-days, so leap years move every date after 28 February without a month table. """ if isinstance(line, bool) or not isinstance(line, int) or line < 1 or line > 99: raise ValueError("line must be a whole number from 1 to 99, received %r" % (line,)) if isinstance(sequence, bool) or not isinstance(sequence, int) or sequence < 1 or sequence > 999: raise ValueError("sequence must be a whole number from 1 to 999, received %r" % (sequence,)) date = parse_iso_date(production_date) day_of_year = days_from_civil(date.year, date.month, date.day) - days_from_civil(date.year, 1, 1) + 1 return "%02d%03d-%02d-%03d" % (date.year % 100, day_of_year, line, sequence)