Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
c7421952
Commit
c7421952
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Use utility function to parse datetime strings
parent
b079138c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/models.py
+8
-8
8 additions, 8 deletions
program/models.py
program/utils.py
+12
-0
12 additions, 0 deletions
program/utils.py
with
20 additions
and
8 deletions
program/models.py
+
8
−
8
View file @
c7421952
...
...
@@ -34,6 +34,7 @@ from django.utils.translation import gettext_lazy as _
from
versatileimagefield.fields
import
VersatileImageField
,
PPOIField
from
steering.settings
import
THUMBNAIL_SIZES
,
AUTO_SET_UNTIL_DATE_TO_END_OF_YEAR
,
AUTO_SET_UNTIL_DATE_TO_DAYS_IN_FUTURE
from
.utils
import
parse_datetime
class
Type
(
models
.
Model
):
...
...
@@ -718,9 +719,8 @@ class Schedule(models.Model):
errors
=
{}
for
ts
in
conflicts
[
'
projected
'
]:
# Ignore past dates
if
timezone
.
make_aware
(
datetime
.
strptime
(
ts
[
'
start
'
],
"
%Y-%m-%d %H:%M:%S
"
))
<=
timezone
.
now
():
if
parse_datetime
(
ts
[
'
start
'
])
<=
timezone
.
now
():
# Ignore past dates
continue
# If no solution necessary
...
...
@@ -802,7 +802,7 @@ class Schedule(models.Model):
create
.
append
(
projected_ts
)
existing_ts
=
TimeSlot
.
objects
.
get
(
pk
=
existing
[
'
id
'
])
existing_ts
.
start
=
datetime
.
strptime
(
ts
[
'
end
'
]
,
'
%Y-%m-%d %H:%M:%S
'
)
existing_ts
.
start
=
parse_
datetime
(
ts
[
'
end
'
])
update
.
append
(
existing_ts
)
# theirs-start
...
...
@@ -824,7 +824,7 @@ class Schedule(models.Model):
create
.
append
(
projected_ts
)
existing_ts
=
TimeSlot
.
objects
.
get
(
pk
=
existing
[
'
id
'
])
existing_ts
.
end
=
datetime
.
strp
time
(
ts
[
'
start
'
]
,
'
%Y-%m-%d %H:%M:%S
'
)
existing_ts
.
end
=
parse_date
time
(
ts
[
'
start
'
])
update
.
append
(
existing_ts
)
# theirs-both
...
...
@@ -851,7 +851,7 @@ class Schedule(models.Model):
create
.
append
(
projected_ts
)
existing_ts
=
TimeSlot
.
objects
.
get
(
pk
=
existing
[
'
id
'
])
existing_ts
.
end
=
datetime
.
strp
time
(
ts
[
'
start
'
]
,
'
%Y-%m-%d %H:%M:%S
'
)
existing_ts
.
end
=
parse_date
time
(
ts
[
'
start
'
])
update
.
append
(
existing_ts
)
projected_ts
=
TimeSlot
.
objects
.
instantiate
(
ts
[
'
end
'
],
existing
[
'
end
'
],
schedule
,
show
)
...
...
@@ -941,8 +941,8 @@ class Schedule(models.Model):
class
TimeSlotManager
(
models
.
Manager
):
@staticmethod
def
instantiate
(
start
,
end
,
schedule
,
show
):
return
TimeSlot
(
start
=
datetime
.
strptime
(
start
,
'
%Y-%m-%d %H:%M:%S
'
),
end
=
datetime
.
strptime
(
end
,
'
%Y-%m-%d %H:%M:%S
'
),
return
TimeSlot
(
start
=
parse_
datetime
(
start
),
end
=
parse_
datetime
(
end
),
show
=
show
,
is_repetition
=
schedule
.
is_repetition
,
schedule
=
schedule
).
generate
()
@staticmethod
...
...
This diff is collapsed.
Click to expand it.
program/utils.py
+
12
−
0
View file @
c7421952
...
...
@@ -18,6 +18,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
datetime
import
datetime
from
django.utils
import
timezone
def
parse_datetime
(
date_string
:
str
)
->
datetime
:
"""
parse a datetime string and return a timezone aware datetime object
"""
try
:
parsed_datetime
=
datetime
.
strptime
(
date_string
,
"
%Y-%m-%d %H:%H:%S
"
)
except
ValueError
:
parsed_datetime
=
datetime
.
strptime
(
date_string
,
"
%Y-%m-%d %H:%M:%S%z
"
)
return
timezone
.
make_aware
(
parsed_datetime
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment