#!/usr/bin/python # Attempt to convert a Seagate date code into a Gregorian calendar date. # Seagate used these date codes for some drives circa 1990-2016 and for # all drives made circa 1999-2015. # # Copyright (C) 2020 The OS/2 Museum # import sys import time from datetime import datetime, timedelta def usage(): print('usage: ' + sys.argv[0] + ' ') args = sys.argv[1:] if len(args) != 1: usage() sys.exit(1) # Get the argument and parse it. datecode = args[0] # The date code must consist of digits. if not datecode.isdigit(): print('error: date code must consist only of digits') sys.exit(2) # The date code must be a four- or five-digit string. if len(datecode) < 4 or len(datecode)> 5: print('error: date code must be 4 or 5 digits') sys.exit(3) # The first two digits specify the fiscal year. It is not entirely clear # when Seagate started used these date codes but it was definitely after # 1980. Assume the range is 1981-2080, although as of 2020 Seagate no longer # uses the date codes. dc = datecode fiscalyear = int(dc[:2]) if fiscalyear> 80: fiscalyear = 1900 + fiscalyear else: fiscalyear = 2000 + fiscalyear # Now remove the year from the date code. dc = dc[2:] # The last digit specifies the day of the week, with day 1 being Saturday. fiscalday = int(dc[-1:]) # Chop off the day of the week. dc = dc[:-1] # The remaining one or two digits specify the week. fiscalweek = int(dc) # Check if the week/day is valid. if fiscalday < 1 or fiscalday> 7: print('error: day of the week (' + str(fiscalday) + ') not in 1-7 range') sys.exit(4) if fiscalweek < 1 or fiscalweek> 53: print('error: fiscal week (' + str(fiscalweek) + ') not in 1-53 range') sys.exit(5) # At this point we have valid input and should be able to convert it into # a Gregorian date. But first we need to do the hard part -- figure out when # exactly Seagate's financial year started. # There does not appear to be any official documentation about that. Based on # Seagate's past SEC filings going back to 1994, Seagate's fiscal year # starts on a Saturday closest to July 1st of the previous calendar year. # Begin by constructing the date of the previous calendar year's July 1st. fy_start_approx = datetime(fiscalyear - 1, 7, 1) # Now find the closest Saturday; that might be any day between June 28th # and July 4th. If July 1st is Wednesday or later, the FY starts in July, # otherwise in June. # Note that in Python, Monday is weekday 0, Sunday is weekday 6. wd = fy_start_approx.weekday() if wd> 1: # July 1st is Wednesday or later; note that if July 1st is a Sunday, # wd will be 6 and the time delta will be negative, wrapping back to # June. tdelta = timedelta(days = 5 - wd) else: # July 1st is Monday or Tuesday; must subtract one week. tdelta = timedelta(days = 5 - wd - 7) # Now get the actual FY start date. fy_start = fy_start_approx + tdelta # Calculate how many days into the fiscal year the drive was made. mfg_delta = timedelta(days = fiscalday - 1, weeks = fiscalweek - 1) # And now just add the delta to the FY start. mfg_date = fy_start + mfg_delta print(mfg_date.strftime("%d %b %Y"))

AltStyle によって変換されたページ (->オリジナル) /