-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for date segment to take a timezone argument #1337
Changes from 4 commits
7b17a65
3d3fe1b
ac81254
f4b1196
15d92fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,27 @@ | |
|
||
from datetime import datetime | ||
|
||
from pytz import (timezone, utc) | ||
|
||
def date(pl, format='%Y-%m-%d', istime=False): | ||
|
||
def date(pl, format='%Y-%m-%d', istime=False, tz=None): | ||
'''Return the current date. | ||
|
||
:param str format: | ||
strftime-style date format string | ||
:param bool istime: | ||
If true then segment uses ``time`` highlight group. | ||
:param string tz: | ||
Timezone parseable by pytz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence does not end with a dot. |
||
|
||
Divider highlight group used: ``time:divider``. | ||
|
||
Highlight groups used: ``time`` or ``date``. | ||
''' | ||
|
||
tztime = utc.localize(datetime.utcnow()).astimezone(timezone(tz)) if tz else datetime.now() | ||
return [{ | ||
'contents': datetime.now().strftime(format), | ||
'contents': tztime.strftime(format), | ||
'highlight_groups': (['time'] if istime else []) + ['date'], | ||
'divider_highlight_group': 'time:divider' if istime else None, | ||
}] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,9 @@ def get_version(): | |
packages=find_packages(exclude=('tests', 'tests.*')), | ||
include_package_data=True, | ||
zip_safe=False, | ||
install_requires=[], | ||
install_requires=[ | ||
'pytz' | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should make this optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you saying making the feature altogether optional if they have pytz installed? That makes sense. |
||
extras_require={ | ||
'docs': [ | ||
'Sphinx', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not correct to use parenthesis here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a python guy, mind mentioning the correct usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not technically incorrect. Just you can drop the parenthesis (leaving everything else as-is) and according to the current style you should drop it unless you are going to have multiline import.