Bladeren bron

fix a bug of datetime and localtime

blueloveTH 2 jaren geleden
bovenliggende
commit
905defb534
2 gewijzigde bestanden met toevoegingen van 5 en 2 verwijderingen
  1. 4 1
      python/datetime.py
  2. 1 1
      src/pocketpy.cpp

+ 4 - 1
python/datetime.py

@@ -94,7 +94,10 @@ class datetime(date):
     @staticmethod
     def now():
         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):
         return f"{self.year}-{self.month:02}-{self.day:02} {self.hour:02}:{self.minute:02}:{self.second:02}"

+ 1 - 1
src/pocketpy.cpp

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