Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
ef6f8d91
Commit
ef6f8d91
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
added function to get a set of weekdays from a date interval
parent
453e4e33
No related branches found
No related tags found
1 merge request
!171
Feature/daily availability
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/utils.py
+22
-0
22 additions, 0 deletions
smash/web/utils.py
with
22 additions
and
0 deletions
smash/web/utils.py
+
22
−
0
View file @
ef6f8d91
# coding=utf-8
# coding=utf-8
from
django.utils
import
timezone
from
django.utils
import
timezone
import
datetime
,
time
import
datetime
,
time
from
datetime
import
timedelta
def
timeit
(
method
):
def
timeit
(
method
):
def
timed
(
*
args
,
**
kw
):
def
timed
(
*
args
,
**
kw
):
...
@@ -21,3 +22,24 @@ def get_today_midnight_date():
...
@@ -21,3 +22,24 @@ def get_today_midnight_date():
today_midnight
=
datetime
.
datetime
(
today
.
year
,
today
.
month
,
today
.
day
,
tzinfo
=
today
.
tzinfo
)
today_midnight
=
datetime
.
datetime
(
today
.
year
,
today
.
month
,
today
.
day
,
tzinfo
=
today
.
tzinfo
)
return
today_midnight
return
today_midnight
def
get_weekdays_in_period
(
fromdate
,
todate
):
'''
fromdate and todate must be generated using datetime.date or datetime.datetime like:
from datetime import date
fromdate = date(2010,1,1)
todate = date(2010,3,31)
fromdate = datetime.datetime(2018, 10, 3, 15, 00, 00)
todate = datetime.datetime.today()
but they must have the same format !
Weekdays are returned as isoweekdays like the form described in week_choices from constants.py (starting at 1)
'''
if
todate
<
fromdate
:
return
set
([])
day_generator
=
(
fromdate
+
timedelta
(
day
)
for
day
in
xrange
((
todate
-
fromdate
).
days
))
weekdays
=
set
([
date
.
isoweekday
()
for
date
in
day_generator
])
return
weekdays
\ No newline at end of file
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