Skip to content
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 storage seconds #1888

Merged
merged 9 commits into from
Jan 27, 2017
Merged

Fix storage seconds #1888

merged 9 commits into from
Jan 27, 2017

Conversation

oakeyc
Copy link
Contributor

@oakeyc oakeyc commented Jan 26, 2017

Fixes #1560, fixes #1563

@azurecla
Copy link

Hi @oakeyc, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!


It looks like you're working at Microsoft (t-cooka). If you're full-time, we DON'T require a contribution license agreement.



If you are a vendor, DO please sign the electronic contribution license agreement. It will take 2 minutes and there's no faxing! https://cla.azure.com.

TTYL, AZPRBOT;

@tjprescott
Copy link
Member

Still have Pylint errors

Copy link
Member

@derekbekoe derekbekoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
When merging, specify a better commit message that "Fix storage seconds".
Maybe something like "[Storage] Allow up to the second precision".

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor changes.

try:
return datetime.strptime(string, form)
except ValueError: # checks next format
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using continue here instead of pass would make the logic more clear and remove the need for the comment. Ultimately they do the same thing in this case.

return datetime.strptime(string, form)
except ValueError: # checks next format
pass
raise ValueError("Not Valid Date Format")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should print out what didn't have a valid date format (the bad input). Otherwise the user won't know which one was screwed up.

'%Y-%m-%dT%HZ', '%Y-%m-%d']
for form in accepted_date_formats:
try:
return datetime.strptime(string, form).strftime(form)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this could be refactored to leverage the existing datetime_type method and avoid duplicating the logic here. You could merge these into one method with a parameter to toggle the behavior:

get_datetime_type_method(to_string=False):
   def datetime_type(string):
      # stuff goes here
      if to_string:
        return datetime.strptime(string, form).strftime(form)
     else:
        return datetime.strptime(string, form)
   return datetime_type

date_format = '%Y-%m-%dT%H:%MZ'
return datetime.strptime(string, date_format)
""" Validates UTC datettime in accepted format. Examples: 2017-12-31T01:11:59Z,
2017-12-31T01:11Z or 2017-12-31T01Z or 2017-12-31 """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks fine exception the format: "2017-12-31T01Z" looks a bit unconventional. It is not one of the format accpetable to Azure Restful API

@tjprescott thoughts?

Copy link
Member

@tjprescott tjprescott Jan 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it isn't acceptable to the API then we shouldn't allow it. However, this is in the KeyVault package. Did you mean to change this?

return datetime.strptime(string, date_format)
def get_datetime_type(to_string):
""" Validates UTC datetime. Examples of accepted forms:
2017-12-31T01:11:59Z,2017-12-31T01:11Z or 2017-12-31T01Z or 2017-12-31 """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this doc string.

''' Validates UTC datettime in format '%Y-%m-%d\'T\'%H:%M\'Z\''. '''
date_format = '%Y-%m-%dT%H:%MZ'
return datetime.strptime(string, date_format)
def get_datetime_type(to_string):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a keyword argument. So when you call this method, you'd have get_datetime_type(to_string=False) etc.

Having get_datetime_type(False) looks odd as I can't tell what False means without having to look at the method definition.

Also, then if a better keyword argument that describes things than to_string can be thought of, this should be changed. Right now, I don't know what to_string actually means so I don't have any suggestions for a better replacement. :)

return datetime.strptime(string, form)
except ValueError:
continue
raise ValueError("Input not of valid format. Valid format: 2000-12-31T12:59:59Z")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to put what the input was that is invalid, not just an example format (though that is good). So it would be:

raise ValueError("Input '{}' is not valid. ... ".format(string))

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should still be improved and a question about KeyVault.

@oakeyc oakeyc merged commit a6bb10b into Azure:master Jan 27, 2017
@oakeyc oakeyc deleted the fix-storage-seconds branch January 27, 2017 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants