28 lines
7.8 KiB
Python
28 lines
7.8 KiB
Python
from pathlib import Path
|
||
import json,re,html,hashlib,subprocess
|
||
from urllib.parse import unquote
|
||
from datetime import datetime
|
||
from zoneinfo import ZoneInfo
|
||
root=Path('/Users/gavrilovdev/tmp/progcode.ru');out=Path('/tmp/progcode-date-content')
|
||
articles=json.loads((root/'web/data/articles.json').read_text());meta=json.loads((root/'docs/rebuild-v2/article-source-metadata.json').read_text());manifest=json.loads((root/'provenance/manifest.json').read_text())
|
||
months=['','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];rows=[]
|
||
for a in articles:
|
||
slug=a['slug'];m=meta[slug];original=next(z for z in manifest['articles'] if unquote(z['slug'])==slug)
|
||
paths=list(dict.fromkeys([m['raw'],'provenance/'+Path(original['file']).name]));evidence=[]
|
||
for path in paths:
|
||
f=root/path;s=f.read_text();match=re.search(r'<time\b[^>]*class="[^"]*entry-date[^\"]*\bpublished\b[^\"]*"[^>]*>.*?</time>',s,re.S)
|
||
assert match,path
|
||
tag=match.group();stamp=re.search(r'datetime="([^"]+)"',tag).group(1);visible=html.unescape(re.sub('<[^>]*>','',tag)).strip();day,month,year=visible.split('.');calendar=f'{year}-{month}-{day}'
|
||
evidence.append(dict(file=path,line=s.count('\n',0,match.start())+1,sha256=hashlib.sha256(f.read_bytes()).hexdigest(),publicationTimeTag=tag,visiblePublicationLabel=visible,publicationCalendarDate=calendar,rawDateTime=stamp,explicitOffset=stamp[-6:],role='V2 selected owning raw' if path==m['raw'] else 'independent previous saved raw cross-check'))
|
||
primary=evidence[0];assert all(z['rawDateTime']==primary['rawDateTime'] and z['publicationCalendarDate']==primary['publicationCalendarDate'] for z in evidence)
|
||
legacy=re.match(r'^/(\d{4})/(\d{2})/(\d{2})/',a['legacyPath']);legacyDate='-'.join(legacy.groups());calendar=primary['publicationCalendarDate'];assert calendar==legacyDate==a['date'][:10];assert a['date']==primary['rawDateTime'];assert primary['explicitOffset']=='+00:00'
|
||
dt=datetime.fromisoformat(a['date']);moscow=dt.astimezone(ZoneInfo('Europe/Moscow')).date().isoformat()
|
||
rows.append(dict(slug=slug,title=a['title'],legacyPath=a['legacyPath'],expectedPublicationCalendarDate=calendar,expectedHistoricalVisibleLabel=primary['visiblePublicationLabel'],expectedRussianDateLabel=f'{int(day)} {months[int(month)]} {year} г.',preserveDateTimeMetadata=a['date'],snapshot=m['snapshot'],evidence=evidence,concordance=dict(visibleLabelEqualsLegacyPath=True,selectedRawEqualsOldRaw=True,encodedOffsetDateEqualsVisibleLabel=True,currentDataEqualsRawDateTime=True),counterfactualMoscowDate=moscow,moscowWouldChangeHistoricalDay=moscow!=calendar,verdict='ACCEPT historical display date; host/viewer timezone conversion must not change it'))
|
||
ledger=dict(domain='progcode.ru',reviewer='/root/content_manager',task='Historical publication calendar contract after P2 timezone rendering defect',commit=subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip(),dataSha256=hashlib.sha256((root/'web/data/articles.json').read_bytes()).hexdigest(),count=14,scope='Date evidence only, not overall restoration acceptance',decision=dict(displayContract='Preserve the historical publication calendar date displayed by entry-date published in original HTML, corroborated by the dated legacy path.',metadataContract='Retain original full ISO datetime including explicit +00:00 unchanged; do not rewrite it to Moscow or move legacy URLs.',implementationVerdict='An explicit UTC formatter satisfies all14 current records because every original timestamp explicitly encodes +00:00 and its UTC date matches the historical visible label and dated path. This is dataset-supported behaviour, not an inference that the author was geographically in UTC.',allTemplates='Use one explicit deterministic contract in article headings, cards, shortlinks, taxonomy/month/author indexes. Do not allow default process or browser timezone.',uncertainty='Raw evidence does not establish author physical timezone or whether old WordPress configuration represented actual physical instants correctly. Do not infer Europe/Moscow from language, ownership or current client timezone.',futureRule='For newly recovered records with another offset or conflicting visible label/path, inspect source and resolve per record; never silently normalize to host timezone.'),mandatoryOpenIssue='webprogcode-v2.6',records=rows)
|
||
(out/'ledger.json').write_text(json.dumps(ledger,ensure_ascii=False,indent=2)+'\n')
|
||
lines=['# Historical date content verdict — all14 inspected','',f"Source commit: `{ledger['commit']}`. Prepared data SHA256: `{ledger['dataSha256']}`.",'','## Decision','','The displayed day is the historical calendar date of the publication as printed in the original article header. It is not a visitor-local rendering of an instant. All14 original visible labels, all14 dated legacy paths, the current metadata and the V2 selected captures agree. Each V2 capture SHA was independently checked; prior saved raw was cross-checked separately where it is another file.','','All14 original publication datetime attributes explicitly end in `+00:00`. Therefore formatting those existing values with an explicit UTC timezone is a small, evidence-supported implementation of the historical calendar contract. It preserves the encoded source offset and the printed original date. It must be used by every article/index/card formatter. Do not shift values or URLs to Europe/Moscow.','','Keep full datetime metadata unchanged. A UTC formatting choice does not prove the author lived in UTC or that WordPress recorded a physically correct instant. Those facts are not recoverable from these HTML tags. The editorially established fact is the date actually printed for readers.','','## Per-page decisions','','| Article | Historical date | datetime preserved | Moscow conversion would change day |','|---|---|---|---|']
|
||
for z in rows:lines.append(f"| `{z['slug']}` | {z['expectedHistoricalVisibleLabel']} | `{z['preserveDateTimeMetadata']}` | {'YES → '+z['counterfactualMoscowDate'] if z['moscowWouldChangeHistoricalDay'] else 'no'} |")
|
||
lines+=['','## Important distinctions','','- Use `time.entry-date.published` only. Later comment timestamps are not publication times.','- The Wayback capture timestamp is a snapshot date, not a publication date.','- GC body refers to the original author article dated14 June2017; this blog publication is24 June2017. They describe different events, not conflicting publication metadata.','- Tilix source interview and CTFE source article likewise have their own publication dates. Preserve this blog’s25 August/26 May dates for its article headers.','- There is no unresolved per-record calendar conflict among these14. The unknown original geographical timezone remains explicitly unknown.','','## Verification acceptance for implementation','','1. Freeze expected dates from ledger.json; do not calculate test expectations with the formatter under test.','2. For every one of14 records render in at least TZ=UTC and TZ=Europe/Moscow; consider America/Los_Angeles and Asia/Tokyo as adversarial defaults. The printed date must remain the ledger date.','3. Check main listing, every article, related/short listings and taxonomy/month indexes use the same calendar contract.','4. Preserve full datetime attribute strings and canonical dated legacy paths byte-for-byte.','5. Specifically regress jQuery12.01.2019, Tilix25.08.2017 and TLS12.07.2017; these are the three records Moscow conversion shifts forward.','','Verdict: content evidence ACCEPT for the date contract. This does not claim the product fix is implemented or tested, and does not alter the mandatory open expanded-recovery issue webprogcode-v2.6. Product files were not changed.']
|
||
(out/'verdict.md').write_text('\n'.join(lines)+'\n')
|
||
print('14/14 concordant; Moscow-shifted:',[z['slug'] for z in rows if z['moscowWouldChangeHistoricalDay']]);print('evidence',out)
|