Hi,

I don't know regular way to change the format of dates for each document.

As a ad-hoc way, you can do that with python codes.
The following code modifies the format of dates at runtime.

from datetime import date


def change_today_fmt(app, docname, source):
    if docname == 'foo':
        app.config.today_fmt = '%B %d, %Y'
    else:
        app.config.today_fmt = '%B/%d/%Y'


def change_last_updated(app, pagename, templatename, context, docname):
    if pagename == 'foo':
        context['last_updated'] = date.today().strftime('%B %d, %Y')
    else:
        context['last_updated'] = date.today().strftime('%B/%d/%Y')


def setup(app):
    app.connect('source-read', change_today_fmt)
    app.connect('html-page-context', change_last_updated)

I know this is a little hacky. But I think this is only way to do that.


Thanks,
Takeshi KOMIYA

2016年8月19日金曜日 0時31分29秒 UTC+9 EMK:
>
> I have a new, related question - can I use two different date formats in 
> the same document? 
>
> I want to have a date that looks like "August 18, 2016" for use in text 
> and also a date that looks like "2016-08-16" for use as the date stamp at 
> the bottom of the page.
>
> I see that I can change the format for two different date elements (use 
> today_fmt and html_last_updated_fmt) but I don't see a way to use the 
> second date element as a subsitution. (It appears in a template footer 
> layout file like this:)
>      {%- if last_updated %}
>         {% trans last_updated=last_updated|e %}Last updated on {{ 
> last_updated }}.{% endtrans %}
>     {%- endif %}
>
> I don't see a way to create a replacement variable and use time format 
> elements (that is, something like .. |update-date| replace::  '%Y-%b-%d' 
> doesn't work).
>
> Any ideas?
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to