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

Date/time range display #26

Open
cogat opened this issue Sep 10, 2012 · 0 comments
Open

Date/time range display #26

cogat opened this issue Sep 10, 2012 · 0 comments

Comments

@cogat
Copy link
Collaborator

cogat commented Sep 10, 2012

Different sites have different preferences for displaying dates and times. Further, different locales will treat dates and times differently.

The date-range and time-range display functions in eventtools (in utils.pprint_timespan) are pretty unwieldy, and difficult to replace with individual preference. This ticket is to implement an easier structure.

The proposal is to remove pprint_timespan, and define the range formats in a setting, which can be overridden or extended on a per-project basis:

PRETTY_DATE_FORMATS = {
    'DEFAULT': {
        'sep': _(u" to "),
        'date': _(u"%(d1)s %(F1)s %(y1)s"),
        'date_range': _(u"%(d1)s %(F1)s %(y1)s %(sep)s %(d2)s %(F2)s %(y2)s"),
        'date_range_within_year': _(u"%(d1)s %(F1)s %(sep)s %(d2)s %(F2)s %(y2)s"),
        'date_range_within_month': _(u"%(d1)s%(sep)s%(d2)s %(F2)s %(y2)s"),
        'month':  _(u"%(F1)s %(y1)s"),
        'month_range':  _(u"%(F1)s %(y1)s %(sep)s %(F2)s %(y2)s"),
        'today': _(u"today, %(d1)s %(F1)s"),
        'tomorrow': _(u"tomorrow, %(d1)s %(F1)s"),
        'time': _(u"%(h1)s:%(i1)s%(a1)s"),
        'time_range': _(u"%(h1)s:%(i1)s%(a1)s%(sep)s%(h2)s:%(i2)s%(a2)s"),
        'time_range_within_ampm': _(u"%(h1)s:%(i1)s%(sep)s%(h2)s:%(i2)s"),
        'hour': _(u"%(h1)s%(a1)s")
        'hour_range': _(u"%(h1)s%(a1)s%(sep)s%(h2)s%(a2)s")
        'hour_rangewithin_ampm': _(u"%(h1)s%(sep)s%(h2)s%(a2)s")
        'midnight': '12 midnight',
        'noon': '12 noon',
        # I think that is all the special cases.
    },
    'BRIEF': {
        'sep': _(u"–"),
        'date': _(u"%(d1)s/%(m1)s"),
        'date_range': _(u"%(d1)s/%(m1)s%(sep)s%(d2)s/%(F2)s"),
        # etc.
    }
}

Then, in templates, the date can be formatted thus:

{{ events.pretty_date }} to use the DEFAULT format
{{ events.pretty_date_BRIEF }} to use the BRIEF format (using getattr magic).

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

No branches or pull requests

1 participant