1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import date
def bulan_tunggakan_berdasarkan_tgl(jatuh_tempo, tgl_hitung):
x = (tgl_hitung.year - jatuh_tempo.year) * 12
y = tgl_hitung.month - jatuh_tempo.month
n = x + y
if n < 0:
return 0
if tgl_hitung.day > jatuh_tempo.day:
n += 1
if n > 24:
return 24
return n
def bulan_tunggakan_berdasarkan_bln(jatuh_tempo, tgl_hitung):
x = (tgl_hitung.year - jatuh_tempo.year) * 12
y = tgl_hitung.month - jatuh_tempo.month
n = x + y
if n < 0:
return 0
#if n == 0:
# if tgl_hitung.day > jatuh_tempo.day:
# return 1
if n > 24:
return 24
return n
def show(data):
print(''.join([
str(data[0]).ljust(12),
str(data[1]).ljust(11),
str(data[2]).rjust(7),
str(data[3]).rjust(7)]))
jatuh_tempo = date(2019, 9, 20)
tgl_bayar_list = [
(2019, 8, 31),
(2019, 9, 20),
(2019, 9, 21),
(2019, 10, 20),
(2019, 10, 21),
(2019, 11, 20),
(2020, 1, 20),
(2020, 1, 21),
]
show(['Jatuh tempo', 'Tgl bayar', 'By tgl', 'By bln'])
for y, m, d in tgl_bayar_list:
tgl_bayar = date(y, m, d)
a = bulan_tunggakan_berdasarkan_tgl(jatuh_tempo, tgl_bayar)
b = bulan_tunggakan_berdasarkan_bln(jatuh_tempo, tgl_bayar)
show([jatuh_tempo, tgl_bayar, a, b])