from __future__ import annotations

from datetime import datetime
from typing import Optional

import pytz


def sync_system_time(is_string_mode: bool = False) -> Optional[str]:
    try:
        time_zone = pytz.timezone("Asia/Shanghai")
        now = datetime.now(time_zone)
        if is_string_mode:
            return now.strftime("%Y-%m-%d-%H-%M-%S")
        return now.strftime("%Y-%m-%d %H:%M:%S")
    except Exception:
        return None