utilora 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- utilora-0.1.0/PKG-INFO +6 -0
- utilora-0.1.0/pyproject.toml +7 -0
- utilora-0.1.0/setup.cfg +4 -0
- utilora-0.1.0/src/utilora/__init__.py +78 -0
- utilora-0.1.0/src/utilora.egg-info/PKG-INFO +6 -0
- utilora-0.1.0/src/utilora.egg-info/SOURCES.txt +6 -0
- utilora-0.1.0/src/utilora.egg-info/dependency_links.txt +1 -0
- utilora-0.1.0/src/utilora.egg-info/top_level.txt +1 -0
utilora-0.1.0/PKG-INFO
ADDED
utilora-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from datetime import date, datetime
|
|
2
|
+
|
|
3
|
+
def check_bool(arg):
|
|
4
|
+
if isinstance(arg,bool):
|
|
5
|
+
raise TypeError("Boolean is not supported")
|
|
6
|
+
|
|
7
|
+
def format_date(arg: int| str| date =0,with_time=False) -> datetime | str:
|
|
8
|
+
check_bool(arg)
|
|
9
|
+
if isinstance(arg,int):
|
|
10
|
+
if arg == 0:
|
|
11
|
+
result = datetime.now()
|
|
12
|
+
else:
|
|
13
|
+
result = datetime.now().strftime('%Y-%m-%d')
|
|
14
|
+
|
|
15
|
+
elif isinstance(arg,str):
|
|
16
|
+
if '.' in arg:
|
|
17
|
+
result = arg.replace('.','-')
|
|
18
|
+
else:
|
|
19
|
+
result = arg.replace('-','.')
|
|
20
|
+
|
|
21
|
+
elif isinstance(arg, datetime):
|
|
22
|
+
if with_time:
|
|
23
|
+
return arg.strftime('%Y-%m-%d %H:%M:%S')
|
|
24
|
+
return arg.strftime('%Y-%m-%d')
|
|
25
|
+
|
|
26
|
+
elif isinstance(arg,date):
|
|
27
|
+
result = arg.strftime('%Y-%m-%d')
|
|
28
|
+
else:
|
|
29
|
+
raise TypeError(f"Unsupported type for argument: {type(arg)}")
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def to_timestamp(arg: int | float | str, with_time=False ) -> int | str:
|
|
34
|
+
check_bool(arg)
|
|
35
|
+
if isinstance(arg,(int, float)):
|
|
36
|
+
try:
|
|
37
|
+
strtime = datetime.fromtimestamp(arg)
|
|
38
|
+
if with_time:
|
|
39
|
+
return strtime.strftime("%Y-%m-%d %H:%M:%S")
|
|
40
|
+
return strtime.strftime("%Y-%m-%d")
|
|
41
|
+
|
|
42
|
+
except OverflowError as e:
|
|
43
|
+
raise OverflowError(f"Invalid date format: {arg}") from e
|
|
44
|
+
|
|
45
|
+
elif isinstance(arg, str):
|
|
46
|
+
try:
|
|
47
|
+
date = datetime.fromisoformat(arg)
|
|
48
|
+
ts = date.timestamp()
|
|
49
|
+
return int(ts)
|
|
50
|
+
except ValueError as e:
|
|
51
|
+
raise ValueError(f"Invalid date format: {arg}") from e
|
|
52
|
+
raise TypeError(f"Unsupported type: {type(arg)}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def format_money(arg)-> str | int:
|
|
56
|
+
check_bool(arg)
|
|
57
|
+
if arg in [None,'','none',[]]:
|
|
58
|
+
return '0'
|
|
59
|
+
|
|
60
|
+
if isinstance(arg,int):
|
|
61
|
+
return f"{arg:,}"
|
|
62
|
+
|
|
63
|
+
if isinstance(arg,str):
|
|
64
|
+
arg = arg.strip()
|
|
65
|
+
if ',' in arg:
|
|
66
|
+
number = arg.replace(",","")
|
|
67
|
+
try:
|
|
68
|
+
return int(number)
|
|
69
|
+
except ValueError as e:
|
|
70
|
+
raise ValueError(f"Invalid money format: {arg}") from e
|
|
71
|
+
else:
|
|
72
|
+
try:
|
|
73
|
+
number = int(arg)
|
|
74
|
+
return number
|
|
75
|
+
except ValueError as e:
|
|
76
|
+
raise ValueError(f"Invalid money format: {arg}") from e
|
|
77
|
+
raise TypeError(f"Unsupported type: {type(arg).__name__}")
|
|
78
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
utilora
|