Browse Source

doc: simple offsets with generic syntax

same as original fix for the Core
fix footer into a single line and add UTC alias notice
pull/2558/head
Maxim Prokhorov 1 year ago
parent
commit
5a74dc146e
1 changed files with 55 additions and 7 deletions
  1. +55
    -7
      code/scripts/tzdata.py

+ 55
- 7
code/scripts/tzdata.py View File

@ -2,8 +2,31 @@ import argparse
import mmap
import os
import pytz
import re
import sys
def maybe_fix_value(value):
return re.sub(r"<[^>]*>", "UNK", value)
def maybe_skip_zone(zone):
return zone.startswith("Etc/") or zone in ("GB-Eire", "W-SU")
def utc_alias(zone):
return zone in (
"Universal",
"UTC",
"UCT",
"Zulu",
"GMT",
"GMT+0",
"GMT-0",
"GMT0",
"Greenwich",
)
def zones(root):
out = []
@ -14,7 +37,7 @@ def zones(root):
continue
m = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
newline = m.rfind(b'\n', 0, len(m) - 1)
newline = m.rfind(b"\n", 0, len(m) - 1)
if newline < 0:
continue
@ -26,21 +49,46 @@ def zones(root):
out.sort(key=lambda x: x[0])
return out
def table(zones):
utcs = []
rows = []
for name, value in zones:
if utc_alias(name):
utcs.append(name)
continue
if maybe_skip_zone(name):
continue
rows.append(f"|{name}|{maybe_fix_value(value)}|")
print("|Name|Value|")
print("|---|---|")
for name, value in zones:
print(f"|{name}|{value}|")
for name in utcs:
print(f"|{name}|UTC0|")
last = ""
for row in rows:
prefix, _, _ = row.partition("/")
if last != prefix:
last = prefix
print("|||")
print(row)
print()
print("---")
print()
print(f"*{pytz.OLSON_VERSION=}*")
print(f"*{pytz.VERSION=}*")
print(f"Generated with *{pytz.OLSON_VERSION=} {pytz.VERSION=}*")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--root",
parser.add_argument(
"--root",
help="Where do we get raw zoneinfo files from",
default=os.path.join(os.path.dirname(pytz.__file__), "zoneinfo"))
default=os.path.join(os.path.dirname(pytz.__file__), "zoneinfo"),
)
args = parser.parse_args()
table(zones(args.root))

Loading…
Cancel
Save