#!/usr/bin/env python3 # Standalone synthetic fixture; no user files or external network. from datetime import date,datetime,timedelta from decimal import Decimal,ROUND_FLOOR from xml.etree import ElementTree as ET def serial(d,system): if system=='1904':return (d-date(1904,1,1)).days return (d-date(1899,12,31)).days+(d>=date(1900,3,1)) def decode(value,system): n=Decimal(str(value));whole=int(n.to_integral_value(rounding=ROUND_FLOOR));seconds=int((n-whole)*86400) if system=='1900' and whole==60:return {'status':'unrepresentable','label':'Excel fictitious 1900-02-29'} base=datetime(1904,1,1) if system=='1904' else datetime(1899,12,31) offset=whole if system=='1904' else whole-(whole>=61) return {'status':'ok','iso':(base+timedelta(days=offset,seconds=seconds)).isoformat()} target=date(2026,10,15);s1900=serial(target,'1900');s1904=serial(target,'1904') assert s1900-s1904==1462 rows=[{'serial':v,'system':system,'decoded':decode(v,system)} for v,system in [(s1900,'1900'),(s1904,'1904'),(s1900,'1904'),(s1904,'1900'),(59,'1900'),(60,'1900'),(61,'1900'),(str(s1900)+'.5','1900')]] xml='' flag=ET.fromstring(xml).find('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}workbookPr').get('date1904') assert flag=='1' and rows[-1]['decoded']['iso'].endswith('12:00:00') result={'date':target.isoformat(),'serial1900':s1900,'serial1904':s1904,'differenceDays':s1900-s1904,'cases':rows,'syntheticWorkbookMetadata':xml,'date1904Flag':flag,'scope':'Pure Python conversion plus minimal OOXML metadata parsing; no Excel application or actual workbook opened. Serial60 is explicitly quarantined, not coerced to a real date.'} import sys,json from datetime import datetime,timezone result={'experiment':'excel-1900-1904-date-systems','executedAt':datetime.now(timezone.utc).isoformat(),'runtime':sys.version.split()[0],'synthetic':True,**result} print(json.dumps(result,ensure_ascii=False,indent=2))