]> git.phdru.name Git - m_lib.git/commitdiff
Use integer division for Py3 compatibility
authorOleg Broytman <phd@phdru.name>
Mon, 25 Jul 2016 16:05:26 +0000 (19:05 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 25 Jul 2016 18:36:49 +0000 (21:36 +0300)
m_lib/opdate.py
m_lib/opstring.py
m_lib/pbar/tty_pbar.py

index 6d230860dcaa3c92d9be8897e04133e801260fd2..e6940a950f80817741213a98c40604ad7ec74b59 100755 (executable)
@@ -110,7 +110,7 @@ def DMYtoDate(Day, Month, Year):
          Year = Year - 1
       Year = Year - MinYear
 
          Year = Year - 1
       Year = Year - MinYear
 
-      return (((Year / 100)*146097) / 4) + (((Year % 100)*1461) / 4) + (((153*Month)+2) / 5)+Day+First2Months
+      return (((Year // 100)*146097) // 4) + (((Year % 100)*1461) // 4) + (((153*Month)+2) // 5)+Day+First2Months
 
 
 def DateToDMY(Julian):
 
 
 def DateToDMY(Julian):
@@ -128,11 +128,11 @@ def DateToDMY(Julian):
          Day = Julian-30
    else:
       I = (4*(Julian-First2Months))-1
          Day = Julian-30
    else:
       I = (4*(Julian-First2Months))-1
-      J = (4*((I % 146097) / 4))+3
-      Year = (100*(I / 146097))+(J / 1461)
-      I = (5*(((J % 1461)+4) / 4))-3
-      Month = I / 153
-      Day = ((I % 153)+5) / 5
+      J = (4*((I % 146097) // 4))+3
+      Year = (100*(I // 146097))+(J // 1461)
+      I = (5*(((J % 1461)+4) // 4))-3
+      Month = I // 153
+      Day = ((I % 153)+5) // 5
       if Month < 10:
          Month = Month + 3
       else:
       if Month < 10:
          Month = Month + 3
       else:
@@ -155,7 +155,7 @@ def IncDate(Julian, Days, Months, Years):
       Day = 28
 
    Year = Year + Years
       Day = 28
 
    Year = Year + Years
-   Year = Year + Months / 12
+   Year = Year + Months // 12
    Month = Month + Months % 12
    if Month < 1:
       Month = Month + 12
    Month = Month + Months % 12
    if Month < 1:
       Month = Month + 12
@@ -181,7 +181,7 @@ def IncDateTrunc(Julian, Months, Years):
       Day = 28
 
    Year = Year + Years
       Day = 28
 
    Year = Year + Years
-   Year = Year + Months / 12
+   Year = Year + Months // 12
    Month = Month + Months % 12
    if Month < 1:
       Month = Month + 12
    Month = Month + Months % 12
    if Month < 1:
       Month = Month + 12
@@ -273,9 +273,9 @@ def TimeToHMS(T):
       return 0, 0, 0
 
    else:
       return 0, 0, 0
 
    else:
-      Hours = T / SecondsInHour
+      Hours = T // SecondsInHour
       T = T - Hours*SecondsInHour
       T = T - Hours*SecondsInHour
-      Minutes = T / SecondsInMinute
+      Minutes = T // SecondsInMinute
       T = T - Minutes*SecondsInMinute
       Seconds = T
 
       T = T - Minutes*SecondsInMinute
       Seconds = T
 
@@ -334,7 +334,7 @@ def RoundToNearestHour(T, Truncate = False):
    Seconds = 0
 
    if not Truncate:
    Seconds = 0
 
    if not Truncate:
-      if Minutes >= (MinutesInHour / 2):
+      if Minutes >= (MinutesInHour // 2):
          Hours = Hours + 1
 
    Minutes = 0
          Hours = Hours + 1
 
    Minutes = 0
@@ -346,7 +346,7 @@ def RoundToNearestMinute(T, Truncate = False):
    Hours, Minutes, Seconds = TimeToHMS(T)
 
    if not Truncate:
    Hours, Minutes, Seconds = TimeToHMS(T)
 
    if not Truncate:
-      if Seconds >= (SecondsInMinute / 2):
+      if Seconds >= (SecondsInMinute // 2):
          Minutes = Minutes + 1
 
    Seconds = 0
          Minutes = Minutes + 1
 
    Seconds = 0
@@ -387,7 +387,7 @@ def IncDateTime(DT1, Days, Secs):
       Secs = -Secs
 
       # adjust the date
       Secs = -Secs
 
       # adjust the date
-      DT2[0] = DT2[0] - Secs / SecondsInDay
+      DT2[0] = DT2[0] - Secs // SecondsInDay
       Secs = Secs % SecondsInDay
 
       if Secs > DT2[1]:
       Secs = Secs % SecondsInDay
 
       if Secs > DT2[1]:
@@ -403,7 +403,7 @@ def IncDateTime(DT1, Days, Secs):
       DT2[1] = DT2[1] + Secs
 
       # adjust date if necessary
       DT2[1] = DT2[1] + Secs
 
       # adjust date if necessary
-      DT2[0] = DT2[0] + DT2[1] / SecondsInDay
+      DT2[0] = DT2[0] + DT2[1] // SecondsInDay
 
       # force time to 0..SecondsInDay-1 range
       DT2[1] = DT2[1] % SecondsInDay
 
       # force time to 0..SecondsInDay-1 range
       DT2[1] = DT2[1] % SecondsInDay
index 0341bced97cfc82d8992b5ce10794aba95682798..cb83a8a92ee9d8222d8dede58e2f45847e9a6398 100755 (executable)
@@ -66,7 +66,7 @@ def CenterCh(S, Ch, Width):
    if len(S) >= Width:
       return S
    else:
    if len(S) >= Width:
       return S
    else:
-      l = (Width - len(S)) / 2
+      l = (Width - len(S)) // 2
       r = Width - len(S) - l
       return Ch*l + S + Ch*r
 
       r = Width - len(S) - l
       return Ch*l + S + Ch*r
 
index 8953f6bf644d6413b4850c75fa925b4fcddca187..0bf4223ed3567503d5358aa7fa88eda6b5ea2bb8 100644 (file)
@@ -56,12 +56,12 @@ class ttyProgressBar:
 
       self.current = current
       current -= self.min
 
       self.current = current
       current -= self.min
-      lng = (current * self.width1) / self.max
+      lng = (current * self.width1) // self.max
 
       if current >= self.max:
          percent = 100
       else:
 
       if current >= self.max:
          percent = 100
       else:
-         percent = (current * 100) / self.max
+         percent = (current * 100) // self.max
 
       flush = False
 
 
       flush = False