# Buggy code
def from_json(cls, json_info):
    from ..util import parse_date

    info = {key: val for key, val in json_info.items() if key in cls.field_names()}
    try:
        info["updated"] = int(
            parse_date(info.get("updated"))
        )  # Cast to int which comes with rounding down
    except (ValueError, TypeError):
        info["updated"] = None
    info["sources"] = info.get("sources") or []

    json_history = info.get("history") or {}
    cast_history = {}

    for method, method_history in json_history.items():
        cast_history[method] = []
        for json_result in method_history:
            assert isinstance(json_result, dict), (
                'Items in Link["history"][method] must be dicts'
            )
            cast_result = ArchiveResult.from_json(json_result)
            cast_history[method].append(cast_result)

    info["history"] = cast_history
    return cls(**info)


# Traceback (ValueError)
/home/kangus/src/archivebox0.4/ArchiveBox/bin/archivebox  init
[*] Updating existing ArchiveBox collection in this folder...
/data/Zalohy/archivebox
------------------------------------------------------------------

[*] Verifying archive folder structure...
√ /data/Zalohy/archivebox/sources
√ /data/Zalohy/archivebox/archive
√ /data/Zalohy/archivebox/logs
√ /data/Zalohy/archivebox/ArchiveBox.conf

[*] Verifying main SQL index and running migrations...
√ /data/Zalohy/archivebox/index.sqlite3

Operations to perform:
Apply all migrations: admin, auth, contenttypes, core, sessions
Running migrations:
No migrations to apply.

[*] Collecting links from any existing indexes and archive folders...
√ Loaded 28875 links from existing main index.
Traceback (most recent call last):
File "/home/kangus/.local/share/virtualenvs/archivebox0.4/lib/python3.8/site-packages/dateutil/parser/_parser.py", line 655, in parse
ret = self._build_naive(res, default)
File "/home/kangus/.local/share/virtualenvs/archivebox0.4/lib/python3.8/site-packages/dateutil/parser/_parser.py", line 1241, in _build_naive
naive = default.replace(**repl)
ValueError: year 1586476777 is out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/kangus/src/archivebox0.4/ArchiveBox/bin/archivebox", line 14, in <module>
archivebox.main(args=sys.argv[1:], stdin=sys.stdin)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/cli/archivebox.py", line 54, in main
run_subcommand(
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/cli/__init__.py", line 55, in run_subcommand
module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/cli/archivebox_init.py", line 32, in main
init(
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/util.py", line 105, in typechecked_function
return func(*args, **kwargs)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/main.py", line 321, in init
fixed, cant_fix = fix_invalid_folder_locations(out_dir=out_dir)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/index/__init__.py", line 572, in fix_invalid_folder_locations
link = parse_json_link_details(entry.path)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/util.py", line 105, in typechecked_function
return func(*args, **kwargs)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/index/json.py", line 100, in parse_json_link_details
return Link.from_json(link_json)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/index/schema.py", line 190, in from_json
info['updated'] = parse_date(info.get('updated'))
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/util.py", line 105, in typechecked_function
return func(*args, **kwargs)
File "/home/kangus/src/archivebox0.4/ArchiveBox/archivebox/util.py", line 144, in parse_date
return dateparser.parse(date)
File "/home/kangus/.local/share/virtualenvs/archivebox0.4/lib/python3.8/site-packages/dateutil/parser/_parser.py", line 1374, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/home/kangus/.local/share/virtualenvs/archivebox0.4/lib/python3.8/site-packages/dateutil/parser/_parser.py", line 657, in parse
six.raise_from(ParserError(e.args[0] + ": %s", timestr), e)
File "<string>", line 3, in raise_from
dateutil.parser._parser.ParserError: year 1586476777 is out of range: 1586476777.093312

# Fixed code
def from_json(cls, json_info):
    from ..util import parse_date

    info = {key: val for key, val in json_info.items() if key in cls.field_names()}
    info["updated"] = parse_date(info.get("updated"))
    info["sources"] = info.get("sources") or []

    json_history = info.get("history") or {}
    cast_history = {}

    for method, method_history in json_history.items():
        cast_history[method] = []
        for json_result in method_history:
            assert isinstance(json_result, dict), (
                'Items in Link["history"][method] must be dicts'
            )
            cast_result = ArchiveResult.from_json(json_result)
            cast_history[method].append(cast_result)

    info["history"] = cast_history
    return cls(**info)