Code

Opened 7 years ago

Closed 4 years ago

#4121 closed (fixed)

DateTime, Date,Time, MonthDay, YearMonth for general usage

Reported by: Ciantic Owned by: garcia_marc
Component: Internationalization Version: master
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: UI/UX:

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)

dateformat.py.diff (2.8 KB) - added by Ciantic 7 years ago.
Adds missing functionality for DateFormat and TimeFormat
dateformat.py.2.diff (2.7 KB) - added by Ciantic 7 years ago.
DateFormat, TimeFormat features for locale reprs. (Few code-beauty errors fixed.)

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by Ciantic

Adds missing functionality for DateFormat and TimeFormat

comment:1 Changed 7 years ago by Ciantic

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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)

Changed 7 years ago by Ciantic

DateFormat, TimeFormat features for locale reprs. (Few code-beauty errors fixed.)

comment:2 Changed 7 years ago by mtredinnick

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 7 years ago by Ciantic

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 Changed 6 years ago by anonymous

  • Cc ciantic@… added
  • Component changed from Core framework to Internationalization
  • Keywords localization i18n local-datetime-format local-date-format local-time-format added

comment:5 Changed 5 years ago by Ciantic

  • milestone set to 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:6 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:7 Changed 5 years ago by benjaoming

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 Changed 5 years ago by garcia_marc

  • Owner changed from nobody to garcia_marc

comment:9 Changed 5 years ago by garcia_marc

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 Changed 4 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.