datasette-render-timestamps/datasette_render_timestamps/__init__.py
import datetimefrom datasette import hookimplmin_timestamp = int(datetime.datetime.timestamp((datetime.datetime.utcnow() - datetime.timedelta(days=5 * 365))))max_timestamp = int(datetime.datetime.timestamp((datetime.datetime.utcnow() + datetime.timedelta(days=5 * 365))))default_format = "%B %d, %Y - %H:%M:%S UTC"@hookimpl()def render_cell(value, column, table, database, datasette):config = (datasette.plugin_config("datasette-render-timestamps", database=database, table=table)or {})if "format" not in config:config["format"] = default_formatif not isinstance(value, int):return Nonecolumns = config.get("columns")# If explicit columns were specified, use thoseif columns is not None:if column not in columns:return Noneelse:# Otherwise automatically detect timestampsif not (min_timestamp < value < max_timestamp):return Nonedt = datetime.datetime.utcfromtimestamp(value)return dt.strftime(config["format"])