import re
import pandas as pd


def tf_minutes(tf: str) -> int:
    m = re.fullmatch(r"(\d+)([mhdw])", tf)
    if not m:
        raise ValueError(f"bad timeframe: {tf}")
    return int(m.group(1)) * {"m": 1, "h": 60, "d": 1440, "w": 10080}[m.group(2)]


def to_utc(x) -> pd.Timestamp:
    t = pd.Timestamp(x)
    return t.tz_localize("UTC") if t.tzinfo is None else t.tz_convert("UTC")


def utcnow() -> pd.Timestamp:
    return pd.Timestamp.now(tz="UTC")
