-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.py
35 lines (25 loc) · 1.02 KB
/
Util.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
from datetime import datetime
def get_formatted_number(type):
current_datetime = datetime.now()
date_str = current_datetime.strftime("%d-%m-%Y") # Format: dd-mm-yyyy
time_str = current_datetime.strftime("%H:%M:%S") # Format: hh:mm:ss
result = str(type) + '#' + date_str.replace('-', '') + time_str.replace(':', '')
return result
def get_formatted_number_without_hash():
current_datetime = datetime.now()
date_str = current_datetime.strftime("%d-%m-%Y") # Format: dd-mm-yyyy
time_str = current_datetime.strftime("%H:%M:%S") # Format: hh:mm:ss
result = date_str.replace('-', '') + time_str.replace(':', '')
return result
def get_current_date():
return datetime.now().strftime("%x")
def get_first_three_characters(value):
if len(value) >= 3:
return value[0:3]
def convert_to_kg(weight, unit):
if unit == 'g' or unit == 'G':
return weight / 1000
elif unit == 'mg' or unit == 'MG' or unit == 'Mg':
return weight / 1000000
else:
return weight