# Path: animanager/datets.py
# def to_ts(date: datetime.date) -> float:
# def to_date(ts: float) -> datetime.date:


import datetime
import logging
import shutil
import sqlite3
from mir import sqlite3m
from animanager import datets
        (6, 'other', 'O')""")


@manager.migration(1, 2)
def _migrate2(conn):
    # Alter anime.
    conn.execute("""\
    CREATE TABLE anime_new (
        aid INTEGER,
        title TEXT NOT NULL UNIQUE,
        type TEXT NOT NULL,
        episodecount INTEGER NOT NULL,
        startdate INTEGER,
        enddate INTEGER,
        PRIMARY KEY (aid)
    )""")

    with conn:
        conn.execute("""\
        INSERT INTO anime_new (aid, title, type, episodecount)
        SELECT aid, title, type, episodes
        FROM anime""")
        # This is done in Python instead of SQL because fuck timezones.
        result = conn.execute('SELECT aid, startdate, enddate FROM anime')
        conn.executemany(
            """\
            UPDATE anime_new
            SET startdate=?, enddate=?
            WHERE aid=?""",
            ([datets.to_ts(_parse_date(startdate)) if startdate else None,

# Path: animanager/datets.py
# def to_ts(date: datetime.date) -> float:
# def to_date(ts: float) -> datetime.date:


# Path: animanager/migrations.py
import datetime
import logging
import shutil
import sqlite3
from mir import sqlite3m
from animanager import datets

        (6, 'other', 'O')""")


@manager.migration(1, 2)
def _migrate2(conn):
    # Alter anime.
    conn.execute("""\
    CREATE TABLE anime_new (
        aid INTEGER,
        title TEXT NOT NULL UNIQUE,
        type TEXT NOT NULL,
        episodecount INTEGER NOT NULL,
        startdate INTEGER,
        enddate INTEGER,
        PRIMARY KEY (aid)
    )""")

    with conn:
        conn.execute("""\
        INSERT INTO anime_new (aid, title, type, episodecount)
        SELECT aid, title, type, episodes
        FROM anime""")
        # This is done in Python instead of SQL because fuck timezones.
        result = conn.execute('SELECT aid, startdate, enddate FROM anime')
        conn.executemany(
            """\
            UPDATE anime_new
            SET startdate=?, enddate=?
            WHERE aid=?""",
            ([datets.to_ts(_parse_date(startdate)) if startdate else None,

              datets.to_ts(_parse_date(enddate)) if enddate else None,