fix a bug of datetime and localtime

This commit is contained in:
blueloveTH 2023-10-30 23:55:06 +08:00
parent 49f70318d9
commit 905defb534
2 changed files with 5 additions and 2 deletions

View File

@ -94,7 +94,10 @@ class datetime(date):
@staticmethod @staticmethod
def now(): def now():
t = localtime() t = localtime()
return datetime(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec) tm_sec = t.tm_sec
if tm_sec == 60:
tm_sec = 59
return datetime(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, tm_sec)
def __str__(self): def __str__(self):
return f"{self.year}-{self.month:02}-{self.day:02} {self.hour:02}:{self.minute:02}:{self.second:02}" return f"{self.year}-{self.month:02}-{self.day:02} {self.hour:02}:{self.minute:02}:{self.second:02}"

View File

@ -1434,7 +1434,7 @@ struct PyStructTime{
tm_mday = tm->tm_mday; tm_mday = tm->tm_mday;
tm_hour = tm->tm_hour; tm_hour = tm->tm_hour;
tm_min = tm->tm_min; tm_min = tm->tm_min;
tm_sec = tm->tm_sec + 1; tm_sec = tm->tm_sec;
tm_wday = (tm->tm_wday + 6) % 7; tm_wday = (tm->tm_wday + 6) % 7;
tm_yday = tm->tm_yday + 1; tm_yday = tm->tm_yday + 1;
tm_isdst = tm->tm_isdst; tm_isdst = tm->tm_isdst;