Opened 18 years ago
Closed 15 years ago
#4121 closed (fixed)
DateTime, Date,Time, MonthDay, YearMonth for general usage
Reported by: | Jari Pennanen | Owned by: | Marc Garcia |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Keywords: | localization i18n local-datetime-format local-date-format local-time-format | |
Cc: | ciantic@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently Django does not let one to use the great functions django.utils.translation.get_date_formats
, get_partial_date_formats
in any handy way.
The following method adds all DateTime, Date, Time, MonthDay, YearMonth for general usage.
Names come from common naming:
c
Datetime, appropriate date and time representation (for example same name in strftime)x
Date, appropriate date representation. e.g. '2007-04-23' (for example same name in strftime)X
Datetime, appropriate date and time representation. e.g. '2007-04-23 4:13' (for example same name in strftime)k
Month day, appropriate month day representation. e.g. 'January 5' (I Invented the "k" naming)K
Year month, appropriate year month representation. e.g. '2007 January' (I invented the "K" naming)
This allows one to use all of the above in date
filter and in now
tag.
Attachments (2)
Change History (12)
by , 18 years ago
Attachment: | dateformat.py.diff added |
---|
comment:1 by , 18 years ago
Fix to the body of document:
- c Datetime, appropriate date and time representation e.g. '2007-04-23 4:13' (for example same name in strftime)
- x Date, appropriate date representation. e.g. '2007-04-23' (for example same name in strftime)
- X Time, appropriate time representation. e.g. '4:13' (for example same name in strftime)
- k Month day, appropriate month day representation. e.g. 'January 5' (I Invented the "k" naming)
- K Year month, appropriate year month representation. e.g. '2007 January' (I invented the "K" naming)
by , 18 years ago
Attachment: | dateformat.py.2.diff added |
---|
DateFormat, TimeFormat features for locale reprs. (Few code-beauty errors fixed.)
comment:2 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 18 years ago
I see this patch or some modification of this patch as necessity. Representations of full formats in own locale is not in wide use and people don't even seem to know about them. Most of programs just happily uses incorrect ways to format datetimes in their templates and views, e.g. hardcoded finnish format "23.4.2007 13:25" or English format. But because Django already supports localed representations why not to give easy way to use them?
One possibility is to create templatetags (similar as now tag) and filters (similar as date filter) for each of those hidden features of Django. But I see it is more sane and natural to add these hidden features to the actual Formatters so using them is most common (e.g. syntax is similar as strftime's syntax).
Please note, that Formatters already consists these types of full formats like:
r
RFC 822 formatted date. 'Thu, 21 Dec 2000 16:01:07 +0200'
So adding these common full formats to formatters does not collide with any "no full formats here" type of idea, which also backs up the idea adding these to the Formatters directly, rather than creating own templatetags and filters.
comment:4 by , 17 years ago
Cc: | added |
---|---|
Component: | Core framework → Internationalization |
Keywords: | localization i18n local-datetime-format local-date-format local-time-format added |
comment:5 by , 16 years ago
milestone: | → post-1.0 |
---|
Is this still relevant? Does Django 1.0 provide a way to use these hidden features in templates (where they are most needed)?
Also the patch may need modifications, as this is old.
comment:7 by , 15 years ago
I think it's more common to want your own customized default representation of dates. So creating your own template filter is the way to go. Luckily you can make DATE_FORMAT localized by using a dummy ugettext and then using it in your own template filter. Like so: http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/
And whatever happened to including these template filters?
comment:8 by , 15 years ago
Owner: | changed from | to
---|
comment:9 by , 15 years ago
Ciantic, it's not clear for me, to understand what's exactly what you want.
Please, take a look at what's done in the soc2009/i18n-improvements branch, specially new features for date filter http://code.djangoproject.com/browser/django/branches/soc2009/i18n-improvements/docs/ref/templates/builtins.txt#L897
With those new features, you'll be able to specify the format for a date (for example 'SHORT_DATETIME_FORMAT'), and Django will display your date in the representation of that format for the current locale.
I can't figure out any situation where it'll be required a new code (letter) for specifying day and month as you propose, please write a detailed example to show us what's in your mind. Or if you think that with those new features, it's possible to do what you wanted, please, let me know, and I'll resolve this ticket as fixed.
Thanks.
comment:10 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think this has been solved with the landing of the locale-aware date/time/number formatting by Marc and Jannis. That work obsoleted the django.utils.translation.get_date_formats()
and get_partial_date_formats()
functions.
Additionally, the 'c'
format specified has been taken over in the mean time.
Closing this ticket as fixed.
Adds missing functionality for DateFormat and TimeFormat