Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nnseva/django-addseconds
Some useful Django template filters for datetime manipulations
https://github.com/nnseva/django-addseconds
datetime django filter template templatetag
Last synced: about 2 months ago
JSON representation
Some useful Django template filters for datetime manipulations
- Host: GitHub
- URL: https://github.com/nnseva/django-addseconds
- Owner: nnseva
- License: lgpl-3.0
- Created: 2021-09-01T16:43:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T09:35:21.000Z (almost 2 years ago)
- Last Synced: 2024-11-08T21:45:57.482Z (about 2 months ago)
- Topics: datetime, django, filter, template, templatetag
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Tests](https://github.com/nnseva/django-addseconds/actions/workflows/test.yml/badge.svg)](https://github.com/nnseva/django-addseconds/actions/workflows/test.yml)
# Django AddSeconds
The [Django AddSeconds](https://github.com/nnseva/django-addseconds) package provides a number
of useful Django template filters for datetime manipulations.## Installation
*Stable version* from the PyPi package repository
```bash
pip install django-addseconds
```*Last development version* from the GitHub source version control system
```
pip install git+git://github.com/nnseva/django-addseconds.git
```## Configuration
Include the `addseconds` application into the `INSTALLED_APPS` list, like:
```python
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'addseconds',
...
]
```## Using
Load the library into your template:
```
{% load addseconds %}
```Use provided template filters as described in the Django documentation.
## Template Filters provided
### addseconds
Adds passed number of seconds to the datetime value, for example:
```
{% load addseconds %}
{{ value|addseconds:3600 }}
```*Notice* that the `value` passed to the template may be `datetime` value, `date` value, `float`, `int`, or `str`,
all of them are converted to the `datetime`. The `date` value is converted to the `datetime` at midnight.
The `float` or `int` value is converted as a unixtime. The `str` value is converted using
`django.utils.dateparse.parse_datetime` call.*Notice* that the template filter argument may be `float` as well as `int`.
### parse_datetime
Calls `django.utils.dateparse.parse_datetime`
```
{% load addseconds %}
{{ "2011-11-01 12:13"|parse_datetime }}
```### parse_date
Calls `django.utils.dateparse.parse_date`
```
{% load addseconds %}
{{ "2011-11-01"|parse_date }}
```### parse_time
Calls `django.utils.dateparse.parse_time`
```
{% load addseconds %}
{{ "12:13"|parse_time }}
```