-
Notifications
You must be signed in to change notification settings - Fork 461
Extract a format_date_with_time helper function #267
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
Extract a format_date_with_time helper function #267
Conversation
The exposes some of the behaviour of format_datetime which might be useful on it's own as it's own function.
Current coverage is
|
|
I'm sorry, but no. This implementation cannot handle timezone support at all. Trying to concatenate |
|
Well with out a function like this you are making life hard for someone who wants a long date but to only give the time to the nearest minute. Very reasonable for example if you are showing the start time of a meeting. It could be implemented with my function like: format_date and format_time are both tz aware and assuming that ts is a datetime with the appropriate time zone info this will just work. I admit it requires the user to do things properly so maybe it should come with a health warning, but it's not too hard to do so and if you don't provide this function people will just have to implement potentially buggy copies of it instead. |
|
It's just bad API design. Formatting functions should accept native datatypes and convert them to localized strings. I don't see the justification in adding a function that can accept arbitrary strings and returns another (partially localized) string. I'm very sorry about this because I've been in your position several times. But this one is not going to happen. |
|
How would you feel about a pull request that augmented format_datetime instead so that it provided options for using different formats for the date and the time? |
|
That is certainly more reasonable. For example, optionally accepting a tuple or list from the |
|
So I was thinking prototype would be something like where date_fmt and time_fmt would be ignored if format is not one of ('full', 'long', 'medium', 'short') date_fmt and time_fmt could the each independantly be one of the standard format names or a custom format. The one thing that it seems to me this misses is support for skeletons (which you might have noticed I'm keen on). But it's easy enough to look up the skeleton from the locale object and pass this in as a custom format. |
The exposes some of the behaviour of format_datetime which might be useful
on it's own as it's own function.
Although this doesn't require the changes I proposed in #265 it is complementary to them.
It allows you to format the date and time using different or explicit formats and then combine them in a locale aware way.