chenhaiyang пре 4 година
родитељ
комит
7a2a90a11c
2 измењених фајлова са 13 додато и 5 уклоњено
  1. 0 5
      app/utils/date.py
  2. 13 0
      app/utils/math.py

+ 0 - 5
app/utils/date.py

@@ -30,8 +30,3 @@ def get_time_str(delta: int = 0, flag: str = 'now') -> str:
 def get_quarter_minutes(time_str: str) -> str:
     temp = arrow.get(time_str, TIME_FMT).timestamp // (15 * 60) * (15 * 60)
     return arrow.get(temp).time().strftime('%H%M%S')
-
-
-if __name__ == '__main__':
-    print(get_time_str())
-    print(get_quarter_minutes(get_time_str()))

+ 13 - 0
app/utils/math.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+
+import math
+import numpy as np
+
+
+def round_half_up(n: float, decimals: int = 0) -> float:
+    if n is np.nan:
+        return n
+    else:
+        multiplier = 10 ** decimals
+
+        return math.floor(n * multiplier + 0.5) / multiplier