Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 447e55df
authored
Aug 17, 2022
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan datetime_from_str
1 parent
b8831ddb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
17 deletions
opensipkd/tools/__init__.py
opensipkd/tools/__init__.py
View file @
447e55d
...
...
@@ -209,27 +209,16 @@ def date_from_str(value):
def
time_from_str
(
value
):
# separator = ":"
value
=
value
.
split
()[
1
]
# dd-mm-yyyy HH:MM:SS
return
value
.
strptime
(
'
%
H:
%
M:
%
S'
)
# return value.strptime('%H:%M:%S')
h
,
m
,
s
=
value
.
split
(
":"
)
# return datetime.time(h, m, s)
return
datetime
.
timedelta
(
hours
=
int
(
h
),
minutes
=
int
(
m
),
seconds
=
int
(
s
))
def
datetime_from_str
(
value
):
# separator = None
dt
=
date_from_str
(
value
)
tm
=
time_from_str
(
value
)
return
dt
+
tm
# value = value.split()[0] # dd-mm-yyyy HH:MM:SS
# for s in ['-', '/', '.']:
# if value.find(s) > -1:
# separator = s
# break
# if separator:
# t = list(map(lambda x: int(x), value.split(separator)))
# y, m, d = t[2], t[1], t[0]
# if d > 999: # yyyy-mm-dd
# y, d = d, y
# else:
# y, m, d = int(value[:4]), int(value[4:6]), int(value[6:])
# return datetime.date(y, m, d)
return
datetime
.
datetime
(
dt
.
year
,
dt
.
month
,
dt
.
day
)
+
tm
def
dmy
(
tgl
):
...
...
@@ -452,6 +441,7 @@ def image_validator(node, value):
raise
colander
.
Invalid
(
node
,
f
'Extension harus salahsatu dari {img_exts}'
)
def
file_response
(
request
,
f
,
filename
,
type
):
response
=
request
.
response
response
.
content_type
=
str
(
type
)
...
...
@@ -459,6 +449,7 @@ def file_response(request, f, filename, type):
response
.
write
(
f
.
read
())
return
response
class
Upload
(
SaveFile
):
def
save_to_file
(
self
,
input_file
,
ext
,
filename
=
None
):
if
filename
:
...
...
@@ -486,7 +477,6 @@ class Upload(SaveFile):
head
,
filename
=
os
.
path
.
split
(
filename
)
return
filename
def
save_fp
(
self
,
upload
):
if
'fp'
not
in
upload
or
upload
[
'fp'
]
==
b
''
:
if
"filename"
in
upload
:
...
...
@@ -519,6 +509,7 @@ class Upload(SaveFile):
with
open
(
out_filename
,
'rb'
)
as
f
:
return
file_response
(
request
,
f
,
filename
,
ext
)
class
UploadBin
(
Upload
):
"""
Compatibility to previous
...
...
@@ -1020,5 +1011,6 @@ def set_user_log(message, request, logobj=None, user_name=None):
message
=
"User {} at Addr {}: {}"
.
format
(
user_name
,
addr
,
message
)
logobj
.
warning
(
message
)
def
includeme
(
config
):
config
.
add_translation_dirs
(
'opensipkd.tools:locale/'
)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment