././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1616706252.273229
calendarweek-0.5.0/CHANGELOG.rst 0000644 0000000 0000000 00000002505 00000000000 013053 0 ustar 00 Change Log
==========
All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog `__
and this project adheres to `Semantic
Versioning `__.
0.5.0
-----
Added
~~~~~
- Class method which gets the last week of a year
Fixed
~~~~~
- Fix year detection at year turns
0.4.7
-----
Changed
~~~~~~~
- Use default language from settings if language is not recognizable
0.4.6
-----
Changed
~~~~~~~
- Don't add encondings in i18n functions
0.4.5
-----
Changed
~~~~~~~
- Convert enums to lists for Django choices
0.4.4
-----
Changed
~~~~~~~
- Leave empty locale unchanged when normalising
0.4.1
-----
Changed
~~~~~~~
- Use system default encoding when normalising locale
0.4.0
-----
Added
~~~~~
- Normalise locales
0.3.1
-----
Fixed
~~~~~
- Fix a type cast for GET parameters
0.3.0
-----
Added
~~~~~
- Allow passing first day of week to i18n_js
- Allow passing locale to all functions
Fixed
~~~~~
- Fix bug in month_names that still had the dummy first element
0.2.1
-----
Changed
~~~~~~~
- Let JS function return a full script
0.2.0
-----
Added
~~~~~
- Functions for month names and abbreviationss
- JSON view for i18n
0.1.1
-----
Added
~~~~~
- Provide functions for tuples and enumerations in i18n module
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616705590.0780551
calendarweek-0.5.0/LICENSE 0000644 0000000 0000000 00000026124 00000000000 012042 0 ustar 00 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 [Copyright holder]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616707212.8748744
calendarweek-0.5.0/README.rst 0000644 0000000 0000000 00000003413 00000000000 012520 0 ustar 00 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
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1616706343.710287
calendarweek-0.5.0/calendarweek/__init__.py 0000644 0000000 0000000 00000000076 00000000000 015571 0 ustar 00 from .calendarweek import CalendarWeek
__version__ = "0.5.0"
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616705590.0780551
calendarweek-0.5.0/calendarweek/calendarweek.py 0000644 0000000 0000000 00000011251 00000000000 016454 0 ustar 00 # Copyright 2019, 2020 Dominik George
# Copyright 2020 Jonathan Weth
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import calendar
from dataclasses import dataclass
from datetime import date, datetime, timedelta
import locale
from typing import Optional, Sequence, Tuple, Union
from .util import normalise_locale
@dataclass
class CalendarWeek:
""" A calendar week defined by year and ISO week number. """
year: Optional[int] = None
week: Optional[int] = None
@classmethod
def day_names(cls, loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of day names for the selected locale. """
with calendar.different_locale(normalise_locale(loc)):
return tuple(calendar.day_name)
@classmethod
def day_abbrs(cls, loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of day name abbreviations for the selected locale. """
with calendar.different_locale(normalise_locale(loc)):
return tuple(calendar.day_abbr)
@classmethod
def month_names(cls, loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of month names for the selected locale. """
with calendar.different_locale(normalise_locale(loc)):
return tuple(calendar.month_name[1:])
@classmethod
def month_abbrs(cls, loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of month name abbreviations for the selected locale. """
with calendar.different_locale(normalise_locale(loc)):
return tuple(calendar.month_abbr[1:])
@classmethod
def from_date(cls, when: date):
""" Get the calendar week by a date object (the week this date is in). """
week = int(when.strftime("%V"))
year = when.year
if when.month == 12 and week == 1:
year += 1
elif when.month == 1 and (week == 52 or week == 53):
year -= 1
return cls(year=year, week=week)
@classmethod
def current_week(cls) -> int:
""" Get the current week number. """
return cls().week
@classmethod
def weeks_within(cls, start: date, end: date) -> Sequence[CalendarWeek]:
""" Get all calendar weeks within a date range. """
if start > end:
raise ValueError("End date must be after start date.")
current = start
weeks = []
while current < end:
weeks.append(cls.from_date(current))
current += timedelta(days=7)
return weeks
@classmethod
def get_last_week_of_year(cls, year: int) -> CalendarWeek:
"""Get the last week of a year."""
last_week = date(year, 12, 28).isocalendar()[1]
return cls(week=last_week, year=year)
def __post_init__(self) -> None:
today = date.today()
if not self.year:
self.year = today.year
if not self.week:
self.week = int(today.strftime("%V"))
def __str__(self) -> str:
return "Week %d (%s to %s)" % (self.week, self[0], self[-1],)
def __len__(self) -> int:
return 7
def __getitem__(self, n: int) -> date:
if n < -7 or n > 6:
raise IndexError("Week day %d is out of range." % n)
if n < 0:
n += 7
return datetime.strptime("%d-%d-%d" % (self.year, self.week, n + 1), "%G-%V-%u").date()
def __contains__(self, day: date) -> bool:
return self.__class__.form_date(day) == self
def __eq__(self, other: CalendarWeek) -> bool:
return self.year == other.year and self.week == other.week
def __lt__(self, other: CalendarWeek) -> bool:
return self[0] < other[0]
def __gt__(self, other: CalendarWeek) -> bool:
return self[0] > other[0]
def __le__(self, other: CalendarWeek) -> bool:
return self[0] <= other[0]
def __gr__(self, other: CalendarWeek) -> bool:
return self[0] >= other[0]
def __add__(self, weeks: int) -> CalendarWeek:
return self.__class__.from_date(self[0] + timedelta(days=weeks * 7))
def __sub__(self, weeks: int) -> CalendarWeek:
return self.__class__.from_date(self[0] - timedelta(days=weeks * 7))
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616705590.0780551
calendarweek-0.5.0/calendarweek/django.py 0000644 0000000 0000000 00000011137 00000000000 015274 0 ustar 00 # Copyright 2019, 2020 Dominik George
# Copyright 2020 Jonathan Weth
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import locale
from typing import Any, List, Optional, Tuple
from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.utils.encoding import DEFAULT_LOCALE_ENCODING
from django.utils.functional import lazy
from django.utils.translation import get_language, to_locale
from .calendarweek import CalendarWeek
def i18n_day_names(loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of day names for the current locale. """
if loc is None:
loc = to_locale(get_language() or settings.LANGUAGE_CODE)
try:
return CalendarWeek.day_names(loc)
except locale.Error:
return CalendarWeek.day_names()
def i18n_day_abbrs(loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of day name abbreviations for the current locale. """
if loc is None:
loc = to_locale(get_language() or settings.LANGUAGE_CODE)
try:
return CalendarWeek.day_abbrs(loc)
except locale.Error:
return CalendarWeek.day_abbrs()
def i18n_month_names(loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of month names for the current locale. """
if loc is None:
loc = to_locale(get_language() or settings.LANGUAGE_CODE)
try:
return CalendarWeek.month_names(loc)
except locale.Error:
return CalendarWeek.month_names()
def i18n_month_abbrs(loc: Optional[str] = None) -> Tuple[str]:
""" Return a tuple of month name abbreviations for the current locale. """
if loc is None:
loc = to_locale(get_language() or settings.LANGUAGE_CODE)
try:
return CalendarWeek.month_abbrs(loc)
except locale.Error:
return CalendarWeek.month_abbrs()
def i18n_day_name_choices(loc: Optional[str] = None) -> Tuple[Tuple[int, str]]:
""" Return an enumeration of day names for the current locale. """
return list(enumerate(i18n_day_names(loc)))
def i18n_day_abbr_choices(loc: Optional[str] = None) -> Tuple[Tuple[int, str]]:
""" Return an enumeration of day name abbreviations for the current locale. """
return list(enumerate(i18n_day_abbrs(loc)))
def i18n_month_name_choices(loc: Optional[str] = None) -> Tuple[Tuple[int, str]]:
""" Return an enumeration of month names for the current locale. """
return list(enumerate(i18n_month_names(loc)))
def i18n_month_abbr_choices(loc: Optional[str] = None) -> Tuple[Tuple[int, str]]:
""" Return an enumeration of month name abbreviations for the current locale. """
return list(enumerate(i18n_month_abbrs(loc)))
def i18n_js(request: HttpRequest) -> HttpResponse:
""" Deliver a JS file containing JS representations of the current locale's
calendar translations. """
# Begin day names at this element
# 0 (default = Monday, 6 = Sunday
first_day = int(request.GET.get("first_day", "0"))
day_indices = list(range(first_day, 7)) + list(range(0, first_day))
def reorder(l: List[Any], i: List[int]) -> List[Any]:
return [l[n] for n in i]
# Get locale from request; can also be used to control caching
loc = request.GET.get("locale", None)
return HttpResponse(
"var calendarweek_i18n = "
+ json.dumps(
{
"day_names": reorder(i18n_day_names(loc), day_indices),
"day_abbrs": reorder(i18n_day_abbrs(loc), day_indices),
"month_names": i18n_month_names(loc),
"month_abbrs": i18n_month_abbrs(loc),
}
),
content_type="text/javascript",
)
i18n_day_names_lazy = lazy(i18n_day_names, tuple)
i18n_day_abbrs_lazy = lazy(i18n_day_abbrs, tuple)
i18n_day_name_choices_lazy = lazy(i18n_day_name_choices, tuple)
i18n_day_abbr_choices_lazy = lazy(i18n_day_abbr_choices, tuple)
i18n_month_names_lazy = lazy(i18n_month_names, tuple)
i18n_month_abbrs_lazy = lazy(i18n_month_abbrs, tuple)
i18n_month_name_choices_lazy = lazy(i18n_month_name_choices, tuple)
i18n_month_abbr_choices_lazy = lazy(i18n_month_abbr_choices, tuple)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616705590.0780551
calendarweek-0.5.0/calendarweek/util.py 0000644 0000000 0000000 00000002022 00000000000 015000 0 ustar 00 # Copyright 2019, 2020 Dominik George
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from locale import getpreferredencoding, locale_alias, locale_encoding_alias
from typing import Optional
def normalise_locale(loc: str, enc: Optional[str] = None) -> str:
loc = locale_alias.get(loc, loc) or ""
if loc:
if enc:
enc = locale_encoding_alias.get(enc.replace("-", ""), enc)
else:
enc = getpreferredencoding()
loc = loc.split(".")[0] + "." + enc
return loc
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616707321.4158523
calendarweek-0.5.0/pyproject.toml 0000644 0000000 0000000 00000002056 00000000000 013747 0 ustar 00 [tool.poetry]
name = "calendarweek"
version = "0.5.0"
description = "Utilities for working with calendar weeks in Python and Django"
authors = ["Dominik George ", "Jonathan Weth "]
license = "Apache-2.0"
homepage = "https://edugit.org/AlekSIS/libs/python-calendarweek"
repository = "https://edugit.org/AlekSIS/libs/python-calendarweek"
documentation = "https://edugit.org/AlekSIS/libs/python-calendarweek"
include = ["CHANGELOG.rst"]
readme = "README.rst"
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Localization",
"Typing :: Typed"
]
[tool.poetry.dependencies]
python = "^3.7"
Django = {version = ">=2.2, <4.0", optional = true}
[tool.poetry.extras]
django = ["Django"]
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
././@PaxHeader 0000000 0000000 0000000 00000000033 00000000000 010211 x ustar 00 27 mtime=1616707323.306439
calendarweek-0.5.0/setup.py 0000644 0000000 0000000 00000005012 00000000000 012540 0 ustar 00 # -*- coding: utf-8 -*-
from setuptools import setup
packages = \
['calendarweek']
package_data = \
{'': ['*']}
extras_require = \
{'django': ['Django>=2.2,<4.0']}
setup_kwargs = {
'name': 'calendarweek',
'version': '0.5.0',
'description': 'Utilities for working with calendar weeks in Python and Django',
'long_description': "python-calendarweek\n===================\n\npython-calendarweek provides a CalendarWeek dataclass for representing one\nweek in a year, and utility functions to work with it in pure Python or\nDjango.\n\n\nUsage\n-----\n\nThe `CalendarWeek` object\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe main interface is the `CalendarWeek` object. The following example shows its\ninterface.\n\n.. code-block:: python\n\n from datetime import date\n from calendarweek import CalendarWeek\n\n # Create an object for the third week in 2012\n week = CalendarWeek(year=2012, week=3)\n\n # Get the current week (or the week for any date)\n week = CalendarWeek.from_date(date.today())\n\n # Short-hand for the current week\n week = CalendarWeek()\n\n # Get all weeks within a date range\n start = date(2012, 3, 18)\n end = date(2012, 4, 19)\n weeks = CalendarWeek.weeks_within(start, end)\n\n # Get the last week of a year\n week = CalendarWeek.get_last_week_of_year(2012)\n\n # Get the Wednesday of the selected week (or any weekday)\n day = week[3]\n\n # Check whether a day is within a week\n is_contained = day in week\n\n # Get the week five weeks later\n week = week + 5\n\n # Additionally, all comparison operators are implemented\n\n\nDjango utilities\n~~~~~~~~~~~~~~~~\n\nSome utilities for Django are contained in the `calendarweek.django` module:\n\n- `i18n_day_names` — Returns a tuple of localised day names\n- `i18n_day_abbrs` — Returns a tuple of abbreviated, localised day names\n- `i18n_month_names` — Returns a tuple of localised month names\n- `i18n_month_abbrs` — Returns a tuple of abbreviated, localised month names\n- All the above for suffixed with `_choices` to get a list of tuples ready for a model\n or form field's `choices`\n- `i18n_js` — A view returning the above as JSON ready to be consumed by a frontend\n",
'author': 'Dominik George',
'author_email': 'nik@naturalnet.de',
'maintainer': None,
'maintainer_email': None,
'url': 'https://edugit.org/AlekSIS/libs/python-calendarweek',
'packages': packages,
'package_data': package_data,
'extras_require': extras_require,
'python_requires': '>=3.7,<4.0',
}
setup(**setup_kwargs)
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1616707323.3066752
calendarweek-0.5.0/PKG-INFO 0000644 0000000 0000000 00000005535 00000000000 012135 0 ustar 00 Metadata-Version: 2.1
Name: calendarweek
Version: 0.5.0
Summary: Utilities for working with calendar weeks in Python and Django
Home-page: https://edugit.org/AlekSIS/libs/python-calendarweek
License: Apache-2.0
Author: Dominik George
Author-email: nik@naturalnet.de
Requires-Python: >=3.7,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Localization
Classifier: Typing :: Typed
Provides-Extra: django
Requires-Dist: Django (>=2.2,<4.0); extra == "django"
Project-URL: Documentation, https://edugit.org/AlekSIS/libs/python-calendarweek
Project-URL: Repository, https://edugit.org/AlekSIS/libs/python-calendarweek
Description-Content-Type: text/x-rst
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