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

format_datetime using 'S...S' format is incorrect #350

Closed
bfordham-ubnt opened this issue Feb 16, 2016 · 4 comments
Closed

format_datetime using 'S...S' format is incorrect #350

bfordham-ubnt opened this issue Feb 16, 2016 · 4 comments

Comments

@bfordham-ubnt
Copy link

When using a format string for format_datetime or format_time using microseconds 'S...', the displayed results are always incorrect if the datetime's microseconds has less than 5 digits.

from datetime import datetime
d = datetime(2016, 2, 15, 8, 3, 1, 799)
print format_datetime(d, 's.S')
>>> 1.8       #should be 1.0
print format_datetime(d, 's.SSSS')
>>> 1.7990   # should be 1.0008

in babel.dates

def format_frac_seconds(self, num):
        value = str(self.value.microsecond)
        return self.format(round(float('.%s' % value), num) * 10**num, num)

should be something like

def format_frac_seconds(self, num):
        value = self.value.microsecond // 1000000
        return self.format(round(value, num) * 10**num, num)
@akx
Copy link
Member

akx commented Feb 21, 2016

@bfordham-ubnt Thanks for the bug report! Since you already have the relevant patch (I took the liberty of adding the proper markup around it) in the issue here, would you be interested in writing a pull request too? If you don't have the time or inclination, it's fine too; just say so, and someone'll pick this up eventually. :)

@shubh1m
Copy link
Contributor

shubh1m commented Feb 21, 2016

@bfordham-ubnt I would want to work on this.

@akx
Copy link
Member

akx commented Feb 22, 2016

@iamshubh22 Go right ahead! :)

@akx
Copy link
Member

akx commented Feb 22, 2016

Marking as in progress for @iamshubh22. (I'm unable to set @iamshubh22 as the assignee for the issue, but anyway.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants