44def delivery_date (start , description ):
55 start_date = datetime .fromisoformat (start )
66
7- match description :
8- case 'NOW' :
9- due_date = start_date + timedelta (hours = 2 )
10- case 'ASAP' :
11- if str ( start_date . time ()) < "13:00:00" :
12- due_date = start_date .replace ( hour = 17 , minute = 0 )
13- else :
14- due_date = (
15- start_date . replace ( hour = 13 , minute = 0 ) +
16- timedelta ( days = 1 )
17- )
18- case 'EOW' :
19- if start_date . isoweekday () < 4 :
20- due_date = (
21- start_date .replace ( hour = 17 , minute = 0 ) +
22- timedelta ( days = 5 - start_date . isoweekday ())
23- )
24- else :
25- due_date = (
26- start_date . replace ( hour = 20 , minute = 0 ) +
27- timedelta ( days = 7 - start_date . isoweekday ())
28- )
29- case description if description . endswith ( 'M' ):
30- month = int ( description [: - 1 ] )
31- target = datetime ( start_date . year , month , 1 , 8 , 0 , 0 )
32-
33- if start_date . month >= target . month :
34- target = target . replace ( year = target .year + 1 )
35- if target . isoweekday () not in ( 6 , 7 ) and target . day in range ( 1 , 8 ):
36- due_date = target
37- else :
38- if target .isoweekday () == 6 :
39- due_date = target + timedelta ( days = 2 )
40- if target . isoweekday () == 7 :
41- due_date = target + timedelta (days = 1 )
42- case description if description . startswith ( 'Q' ):
43- target = int ( description [ 1 :])
44- current = (( start_date . month + 2 ) // 3 )
45- month = { "Q1" : 4 , "Q2" : 7 , "Q3" : 10 , "Q4" : 1 }[ description ]
46- rollover = 1 if ( current > target or target == 4 ) else 0
47-
48- due_date = start_date . replace (
49- start_date . year + rollover , month , 1 , 8 , 0 , 0
50- ) - timedelta ( days = 1 )
51-
52- if due_date . isoweekday () == 6 :
53- due_date -= timedelta ( days = 1 )
54- if due_date .isoweekday () == 7 :
55- due_date -= timedelta (days = 2 )
56-
57- return due_date .isoformat ()
7+
8+ if description == 'NOW' :
9+ due_date = start_date + timedelta (hours = 2 )
10+
11+ if description == 'ASAP' :
12+ if str ( start_date .time ()) < '13:00:00' :
13+ due_date = start_date . replace ( hour = 17 , minute = 0 )
14+ else :
15+ due_date = (
16+ start_date . replace ( hour = 13 , minute = 0 ) +
17+ timedelta ( days = 1 )
18+ )
19+
20+ if description == 'EOW' :
21+ if start_date .isoweekday () < 4 :
22+ due_date = (
23+ start_date . replace ( hour = 17 , minute = 0 ) +
24+ timedelta ( days = 5 - start_date . isoweekday ())
25+ )
26+ else :
27+ due_date = (
28+ start_date . replace ( hour = 20 , minute = 0 ) +
29+ timedelta ( days = 7 - start_date . isoweekday ())
30+ )
31+
32+ if description . endswith ( 'M' ):
33+ month = int ( description [: - 1 ])
34+ target = datetime ( start_date .year , month , 1 , 8 , 0 , 0 )
35+
36+ if start_date . month > = target . month :
37+ target = target . replace ( year = target . year + 1 )
38+ if target .isoweekday () not in ( 6 , 7 ) and target . day in range ( 1 , 8 ) :
39+ due_date = target
40+ else :
41+ if target . isoweekday () == 6 : due_date = target + timedelta (days = 2 )
42+ if target . isoweekday () == 7 : due_date = target + timedelta ( days = 1 )
43+
44+ if description . startswith ( 'Q' ):
45+ target = int ( description [ 1 :])
46+ current = (( start_date . month + 2 ) // 3 )
47+ month = { "Q1" : 4 , "Q2" : 7 , "Q3" : 10 , "Q4" : 1 }[ description ]
48+ rollover = 1 if ( current > target or target == 4 ) else 0
49+
50+ due_date = start_date . replace (
51+ start_date . year + rollover , month , 1 , 8 , 0 , 0
52+ ) - timedelta ( days = 1 )
53+
54+ if due_date .isoweekday () == 6 : due_date -= timedelta ( days = 1 )
55+ if due_date . isoweekday () == 7 : due_date -= timedelta (days = 2 )
56+
57+ return due_date .isoformat ()
0 commit comments