Skip to content

Commit

Permalink
fix timezone (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT authored Jul 30, 2024
1 parent b0e26f6 commit f0a4a3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions swanlab/cli/commands/task/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
from swanlab.package import get_key, get_experiment_url
from swanlab.api import terminal_login, create_http, LoginInfo, get_http
from swanlab.error import KeyFileError, ApiError
from datetime import datetime
from datetime import datetime, timedelta
from typing import Optional
from swanlab.log import swanlog
import sys
import click
import time


def validate_six_char_string(_, __, value):
Expand Down Expand Up @@ -84,7 +85,12 @@ def fmt_time(date: str = None):
if date is None:
return None
date = date.replace("Z", "+00:00")
return datetime.fromisoformat(date).strftime("%Y-%m-%d %H:%M:%S")
# 获取当前计算机时区的时差(以秒为单位)
local_time_offset = time.altzone if time.localtime().tm_isdst else time.timezone
local_time_offset = timedelta(seconds=-local_time_offset)
local_time = datetime.fromisoformat(date) + local_time_offset
# 将 UTC 时间转换为本地时间
return local_time.strftime("%Y-%m-%d %H:%M:%S")


class UseTaskHttp:
Expand Down
2 changes: 1 addition & 1 deletion swanlab/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swanlab",
"version": "0.3.15-beta",
"version": "0.3.15-beta.1",
"description": "",
"python": "true"
}

0 comments on commit f0a4a3e

Please sign in to comment.