Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Chronos
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Chronos
Merge requests
!38
Move prev/next functions to TimePeriod model
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Move prev/next functions to TimePeriod model
refactor/move-prev-next-functions-to-models
into
master
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
Jonathan Weth
requested to merge
refactor/move-prev-next-functions-to-models
into
master
5 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
Close
#65 (closed)
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
f70897b4
1 commit,
5 years ago
3 files
+
52
−
59
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
aleksis/apps/chronos/util/prev_next.py deleted
100644 → 0
+
0
−
48
Options
from
datetime
import
timedelta
,
date
,
time
from
typing
import
Optional
,
Tuple
from
calendarweek
import
CalendarWeek
from
django.urls
import
reverse
from
django.utils
import
timezone
from
..models
import
TimePeriod
def
get_next_relevant_day
(
day
:
Optional
[
date
]
=
None
,
time
:
Optional
[
time
]
=
None
,
prev
:
bool
=
False
)
->
date
:
"""
Returns next (previous) day with lessons depending on date and time
"""
if
day
is
None
:
day
=
timezone
.
now
().
date
()
if
time
is
not
None
and
not
prev
:
if
time
>
TimePeriod
.
time_max
:
day
+=
timedelta
(
days
=
1
)
cw
=
CalendarWeek
.
from_date
(
day
)
if
day
.
weekday
()
>
TimePeriod
.
weekday_max
:
if
prev
:
day
=
cw
[
TimePeriod
.
weekday_max
]
else
:
cw
+=
1
day
=
cw
[
TimePeriod
.
weekday_min
]
elif
day
.
weekday
()
<
TimePeriod
.
weekday_min
:
if
prev
:
cw
-=
1
day
=
cw
[
TimePeriod
.
weekday_max
]
else
:
day
=
cw
[
TimePeriod
.
weekday_min
]
return
day
def
get_prev_next_by_day
(
day
:
date
,
url
:
str
)
->
Tuple
[
str
,
str
]:
"""
Build URLs for previous/next day
"""
day_prev
=
get_next_relevant_day
(
day
-
timedelta
(
days
=
1
),
prev
=
True
)
day_next
=
get_next_relevant_day
(
day
+
timedelta
(
days
=
1
))
url_prev
=
reverse
(
url
,
args
=
[
day_prev
.
year
,
day_prev
.
month
,
day_prev
.
day
])
url_next
=
reverse
(
url
,
args
=
[
day_next
.
year
,
day_next
.
month
,
day_next
.
day
])
return
url_prev
,
url_next
Loading