-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: Add new datetime_format module.
- Loading branch information
Espen A. Kristiansen
committed
Aug 30, 2018
1 parent
54ec2d1
commit c380e32
Showing
5 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import arrow | ||
from django.conf import settings | ||
from django.template import defaultfilters | ||
|
||
|
||
def format_datetime_in_timezone(datetime_object, datetime_format='DATETIME_FORMAT', timezone=settings.TIME_ZONE): | ||
""" | ||
Format a datetime object in a timezone. | ||
Args: | ||
datetime_object (datetime.datetime): Datetime object to format. | ||
datetime_format (str): A Django datetime formatting string name, such as ``"DATETIME_FORMAT"``, | ||
``"SHORT_DATETIME_FORMAT``", ``"DATE_FORMAT"``, ... | ||
timezone (str): Defaults to ``settings.TIME_ZONE``. The datetime is converted to | ||
this timezone. So if you use UTC in the database, and want to present another | ||
timezone, this will convert it correctly. | ||
Returns: | ||
str: The formatted datetime. | ||
""" | ||
return defaultfilters.date(arrow.get(datetime_object).to(timezone).datetime, datetime_format) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
################################## | ||
ievv_opensource 5.10.0 releasenotes | ||
################################## | ||
|
||
************ | ||
New features | ||
************ | ||
- New ``utils.datetime_format`` module - see :doc:`/utils.datetime_format`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
############################################################## | ||
`utils.datetime_format` --- Utilities for formatting datetimes | ||
############################################################## | ||
|
||
.. currentmodule:: ievv_opensource.utils.datetime_format | ||
.. automodule:: ievv_opensource.utils.datetime_format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
'termcolor', | ||
'psutil', | ||
'future', | ||
'arrow', | ||
], | ||
entry_points={ | ||
'console_scripts': [ | ||
|