-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmam_tools.py
50 lines (45 loc) · 1.54 KB
/
mam_tools.py
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
# -*- coding: utf8 -*-
from datetime import datetime,date,timedelta
import re
import pprint
import unicodedata
def convert_str_log(s):
return unicodedata.normalize('NFKD', s).encode('ascii','ignore')
class ppl():
def __init__(self, *objs):
self.objs = objs
def __repr__(self):
return " ".join([pprint.pformat(obj) for obj in self.objs])
class pl():
def __init__(self, *objs):
self.objs = objs
def __repr__(self):
return convert_str_log(u" ".join([str(obj) for obj in self.objs]))
def verif_heures(hdebut, hfin, fin_obligatoire=False):
try:
matchObj = re.match( r"^(\d+?)[- _.:;'hH]?(\d{1,2})[mM]?$", hdebut)
if matchObj:
hdebut = "{:%H:%M}".format(datetime.strptime(matchObj.group(1)+":"+matchObj.group(2),"%H:%M"))
else:
return False
if not fin_obligatoire and (hfin == False or hfin == ""):
return [hdebut,""]
matchObj = re.match( r"^(\d+?)[- _.:;'hH]?(\d{1,2})[mM]?$", hfin)
if matchObj:
hfin = "{:%H:%M}".format(datetime.strptime(matchObj.group(1)+":"+matchObj.group(2),"%H:%M"))
else:
return False
return [hdebut,hfin]
except:
return False
def conv_str2minutes(str):
if str == False or str == "":
str = "0:0"
if ":" in str:
(h,m) = str.split(":") # 11:45
else:
(h,min) = str.split("h ") # 3h 30m
m=min[:2]
return (int(h)*60 + int(m))
def conv_minutes2str(min):
return "{0}h {1:02d}m".format(min/60, min%60) # 3h 30m