-
Notifications
You must be signed in to change notification settings - Fork 451
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
Fix #325 Support more format for timezone #338
Conversation
Current coverage is
|
Current coverage is
|
@@ -395,7 +395,9 @@ def get_timezone_gmt(datetime=None, width='long', locale=LC_TIME): | |||
|
|||
:param datetime: the ``datetime`` object; if `None`, the current date and | |||
time in UTC is used | |||
:param width: either "long" or "short" | |||
Added new parameter for width to resolve bug #325 |
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.
This doesn't need to be in the docstring.
@sachinpali146 Thank you for the patch! However please review the code formatting comments made by @gitmate-bot, above, and my inline comments about the code itself. In addition, I don't see test cases for the new formatting; could you please add some? Extra credit if some tests match the examples in the TR35 (such as |
@akx Thanks for the suggestions, I will work on them. I am working on open source project for first time so I will be needing some guidance. |
@@ -1282,6 +1284,16 @@ def format_timezone(self, char, num): | |||
return get_timezone_name(self.value.tzinfo, width, | |||
uncommon=True, locale=self.locale) | |||
return get_timezone_location(self.value.tzinfo, locale=self.locale) | |||
# Included additional elif condition to add support for 'X' in timezone format | |||
elif char in "xX": | |||
if get_timezone_gmt(self.value, width='short', locale=self.locale)=='+0000' and char == 'X': |
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.
Hmm... It still feels kind of wasteful to have get_timezone_gmt
go through actually formatting the date just so its return value could be turned into a zero :)
I think it might be better to actually add an argument to get_timezone_gmt
, something like return_z
(optional, false by default), which, when set to True, would cause its logic to short-circuit to returning "Z"
directly after it has calculated that the offset would in fact be zero.
What do you think?
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.
Yes, initially I was also thinking to add some argument in get_timezone_gmt
function, should I go ahead and add the functionality
@akx Can you please help me in understanding how codecov works and why commits are failing. |
@sachinpali146 Sure. Codecov measures the code coverage for the tests that are being run for the code. In this particular case,
means that of the lines you have changed, only 66% are covered by the test suite. Likewise,
means that while the complete test coverage of the project had been 89.47% before this PR, with the added code it's dropped down to 89.03%. What this means, all in all, is that there's new code that is left untested, and the way to fix it is to add tests that cover all of the new behavior. So -- could you write tests to cover the new behavior you've implemented? |
@akx Thanks for the guidance about code coverage. I had added the test cases for the patch and it covered 100% patch code and also increased the project code coverage :) |
:param locale: the `Locale` object, or a locale string | ||
:param return_z: True or False; Function returns indicator "Z" | ||
when local time offset is 0 | ||
:param x_format: True or False; Function returns The ISO8601 basic format |
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.
The z
flag is fine, but I think this flag needs to be rethought, since it looks like it only affects one situation anyway.
Maybe make this another width
? iso8601_short
, for instance?
So iso8601
would always return the +HH:MM format, and iso8601_short
would return either +HH
or +HH:MM
?
Very impressive work with the tests, good job! 🎉 There's still a couple things I'd like to address; see the inline comments, and also pay attention to Gitmate's stylistic complaints. (You seem to be missing a couple whitespaces after commas and so on. :) ) |
@@ -437,7 +454,10 @@ def get_timezone_location(dt_or_tzinfo=None, locale=LC_TIME): | |||
the timezone; if `None`, the current date and time in | |||
UTC is assumed | |||
:param locale: the `Locale` object, or a locale string | |||
:return: the localized timezone name using location format | |||
:param return_city: True or False |
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.
The parameter description should include what it does too. Maybe something like
Return only the exemplar city for the time zone when true
?
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 did added that info but at wrong location, Should I move it up?
:param return_city: True or False
:return: the localized timezone name using location format;
if return_city is True then return The exemplar city (location) for the time zone
@sachinpali146 The PR is starting to look very good now! Could you just squash the changes into a couple commits with messages following the Writing Good Commits rules? Maybe
If you're unfamiliar with rewriting commits like this, try the Git Book's Interactive Staging tutorial. I'd personally do something like (assuming we're starting from this branch's HEAD and a remote called $ git fetch --all # (get all changes from all remotes)
$ git rebase upstream/master # (rebase your changes on top of the current master; there should not be any conflicts to resolve)
$ git reset upstream/master # (reset your repo to a state where your changes are intact in the working tree but the commits aren't there)
$ git add -p # (include the first set of changes)
$ git commit # (write a fantastic commit message)
$ git add -u # (to add the rest of the updated files)
$ git commit # (write another fantastic message)
$ git push -f # (force-push to your PR branch) |
Added argument 'return_z' and two values 'iso8601' and 'iso8601_short' in argument width in get_timezone_gmt(), 'return_city' argument is add in get_timezone_location() and 'return_zone' in get_timezone_name() so we can implement iso8601 timezone patterns.
Thank you very much for the contributions, @sachinpali146! And thanks for putting up with my nitpicking. This is an exemplary patch. :) Merging this -- have a great weekend! |
Fix #325 Support more format for timezone
Thank you @akx for your patience, I had learned lot of thing by working on this PR and your continuous guidance. It is your nitpicking which has helped me to become open source society contributor :) |
Added the Support for timezone format 'ZZZZZ' and 'X'