Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-calendarweek
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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®
Libraries
python-calendarweek
Commits
2e10b589
Verified
Commit
2e10b589
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Document usage in README
parent
93e0afcf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.rst
+57
-0
57 additions, 0 deletions
README.rst
with
57 additions
and
0 deletions
README.rst
+
57
−
0
View file @
2e10b589
...
...
@@ -4,3 +4,60 @@ python-calendarweek
python-calendarweek provides a CalendarWeek dataclass for representing one
week in a year, and utility functions to work with it in pure Python or
Django.
Usage
-----
The `CalendarWeek` object
~~~~~~~~~~~~~~~~~~~~~~~~~
The main interface is the `CalendarWeek` object. The following example shows its
interface.
.. code-block:: python
from datetime import date
from calendarweek import CalendarWeek
# Create an object for the third week in 2012
week = CalendarWeek(year=2012, week=3)
# Get the current week (or the week for any date)
week = CalendarWeek.from_date(date.today())
# Short-hand for the current week
week = CalendarWeek()
# Get all weeks within a date range
start = date(2012, 3, 18)
end = date(2012, 4, 19)
weeks = CalendarWeek.weeks_within(start, end)
# Get the last week of a year
week = CalendarWeek.get_last_week_of_year(2012)
# Get the Wednesday of the selected week (or any weekday)
day = week[3]
# Check whether a day is within a week
is_contained = day in week
# Get the week five weeks later
week = week + 5
# Additionally, all comparison operators are implemented
Django utilities
~~~~~~~~~~~~~~~~
Some utilities for Django are contained in the `calendarweek.django` module:
- `i18n_day_names` — Returns a tuple of localised day names
- `i18n_day_abbrs` — Returns a tuple of abbreviated, localised day names
- `i18n_month_names` — Returns a tuple of localised month names
- `i18n_month_abbrs` — Returns a tuple of abbreviated, localised month names
- All the above for suffixed with `_choices` to get a list of tuples ready for a model
or form field's `choices`
- `i18n_js` — A view returning the above as JSON ready to be consumed by a frontend
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