Changing the format of entry dates in English

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Carl @ ATS
Regular
Posts: 55
Joined: Fri Jun 07, 2013 11:41 am
Location: Fürstenfeldbruck, Germany
Contact:

Changing the format of entry dates in English

Post by Carl @ ATS »

Hi,

Whenever I publish new entries for my English blog, the date of the entry that appears above them gets written this way:

FRIDAY, SEPTEMBER 20. 2013

Can anyone tell me how to get Serendipity to write "Friday, 20 September 2013" instead, please?
In other words, using:
- normal spelling with a mixture of upper- and lower-case spelling, not just upper- or lower-case
- British-style dates rather than American (i.e. with the date before the month)
- no full stop before the year (which, incidentally, is wrong in English anyway; it ought to be a comma for American English).

I realise upper and lower case are part of CSS, but the format I want is a mixture of both; how do you get that? I also realise that entry dates are created using variables, but I'm not a programmer and don't know how to adapt the programming. :shock: Is there a (relatively simple) way of adapting the date format, and which file does this bit of code need to be inserted in?

The template I'm currently using for the blog is "Competition" and I'm using the latest build, 1.7.3.

I'd appreciate any ideas. The lower-case issue isn't very important, really, but I would like to use a British date format if possible.

Regards

Carl

My blog's here: www.ampertrans.de/blog/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Changing the format of entry dates in English

Post by garvinhicking »

Hi!

There are multiple ways to deal with this:

1. Edit lang/(UTF-8)/serendipity_lang_XX.inc.php for the language that your blog's runnin in (i.e. "en" or "de", or whatever). Change the constant:

Code: Select all

@define('DATE_FORMAT_ENTRY', '%A, %B %e. %Y');
to:

Code: Select all

@define('DATE_FORMAT_ENTRY', '%A, %e %B %Y');
2. Edit your custom template files (usually only entries.tpl) that refer to DATE_FORMAT_ENTRY and replace it with a string that you want your formatting to appear as. I.e. change:

Code: Select all

{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}
to:

Code: Select all

{$dategroup.date|@formatTime:"%A, %e %B %Y'"}
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Carl @ ATS
Regular
Posts: 55
Joined: Fri Jun 07, 2013 11:41 am
Location: Fürstenfeldbruck, Germany
Contact:

Re: Changing the format of entry dates in English

Post by Carl @ ATS »

Thanks very much, Garvin. That was very helpful. :D

The only thing I've altered in your snippet of code is the apostrophe after the year, which I got rid of, leaving this: {$dategroup.date|@formatTime:"%A, %e %B %Y"}. I edited entries.tpl in my template folder.

Thanks again - that's my main issue sorted out. (I'll just skip the lower-case one, I think.)

Best,

Carl
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Changing the format of entry dates in English

Post by yellowled »

Carl @ ATS wrote:(I'll just skip the lower-case one, I think.)
In your style.css, find

Code: Select all

.serendipity_date {
    font-family: Arial, Geneva, Helvetica, sans-serif;
    font-size: x-small;
    color: #607080;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 95%;
    padding-bottom: 10px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 3px;
    text-align: left;
}
and remove only this line

Code: Select all

text-transform: uppercase;
YL
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Changing the format of entry dates in English

Post by yellowled »

Also, since competition is part of the s9y core, be advised that your changes in entries.tpl and style.css (basically, in any file which is part of competition) will be overwritten. You might want to move your edited copy to a seperate template directory and use this “forked” templates.

YL
Carl @ ATS
Regular
Posts: 55
Joined: Fri Jun 07, 2013 11:41 am
Location: Fürstenfeldbruck, Germany
Contact:

Re: Changing the format of entry dates in English

Post by Carl @ ATS »

Morning YellowLed,

Thanks for giving me these two additional tips, which are very useful.

I've already noticed that s9y doesn't want me to change anything in the files as "error" messages now appear whenever I try and verify the installation - due to the modifications I've made in the core files, as you say. This is a bit annoying since the errors aren't mistakes or unexpected file corruptions - it would be nicer (= more reassuring) to get a "clean" report, as it were, but how do I get that, I wonder? If I moved the files I've changed "elsewhere" (where exactly?) and left the original files untouched, that would presumably work, but what references in files (i.e. paths) need to be changed for s9y to find the edited files and display my blog the way I want it to? Any ideas?

Regards

Carl

www.ampertrans.de/blog/ (s9y 1.7.3)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Changing the format of entry dates in English

Post by Timbalu »

Just to answer this:
The Serendipity Integrity Check, checks whether files are corruped, changed or touched, and, in any case, responds "file-xy corrupt or modified: failed verification".
This works for all released (zipped) files via checksums. Changing core files in general is not recommended, if not really in need.

Now, if you really need to change something in the core, better note it somewhere, to remember this for yourself. The checksum check does not know whether the changing person pursued good or bad intentions. If the change is an enhancement, discuss with us here, to change for us all.

If you need to change any files in a core delivered template, like Garvin suggested for the lang above, copy the template in the template folder, rename the directory and edit the info.txt, to hold that new name. Now you can easily switch to that theme in backends "Change Style" and edit it in various ways without the checksum validator noticing. In your case: templates/competition.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Carl @ ATS
Regular
Posts: 55
Joined: Fri Jun 07, 2013 11:41 am
Location: Fürstenfeldbruck, Germany
Contact:

Re: Changing the format of entry dates in English

Post by Carl @ ATS »

Thanks for the explanation, Ian.

Regards

Carl
Carl @ ATS
Regular
Posts: 55
Joined: Fri Jun 07, 2013 11:41 am
Location: Fürstenfeldbruck, Germany
Contact:

Re: Changing the format of entry dates in English

Post by Carl @ ATS »

Hi everyone,

I'm currently trying out some of the alternative templates s9y provides and would like to use "Bulletproof" for a while as I like the clear layout. :D Can anyone advise me how to change the current date format, please? The date of my last blog post is "Friday, January 24. 2014", for example, whereas I'd like it to be "Friday, 24 January 2014".

I encountered the same issue last year with "Competition", but was able to adjust the date using Garvin's tips (see above). For some reason, these don't seem to work for "Bulletproof", though - none of the changes has had any effect. :shock:

It looks as though I could set the date format from s9y's control panel under "Appearance" > "Manage styles", but if I click on the drop-down in the row called "Dateformatting", the British English format I want (%A, %e %B %Y) doesn't seem to be listed (see the attached screen shot). Can I set the date format anywhere else, I wonder?

Regards,

Carl

P.S. As an aside, if you look at the first entry, you'll see the current setting, which contains a mistake - a full stop appears before the year instead of a comma. Would someone correct that, please?
Attachments
The formatting that's set contains a mistake, and none of the other formats seem to fit the bill
The formatting that's set contains a mistake, and none of the other formats seem to fit the bill
date_formatting.gif (9.49 KiB) Viewed 6514 times
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Changing the format of entry dates in English

Post by Don Chambers »

You can add that option to the list of available date format choices. In your template folder, edit the file config.inc.php using a simple text editor. At approximately line 130, you will find the date formatting options defined as follows:

Code: Select all

    array(
        'var'           => 'date_format',
        'name'          => GENERAL_PLUGIN_DATEFORMAT . " (http://php.net/strftime)",
        'type'          => 'select',
        'default'       => DATE_FORMAT_ENTRY,
        'select_values' => array(DATE_FORMAT_ENTRY => DATE_FORMAT_ENTRY,
                                 '%a, %e. %B %Y' => '%a, %e. %B %Y',
                                 '%d-%m-%y' => '%d-%m-%y',
                                 '%m-%d-%y' => '%m-%d-%y',
                                 '%a %d-%m-%y' => '%a %d-%m-%y',
                                 '%a %m-%d-%y' => '%a %m-%d-%y',
                                 '%b %d' => '%b %d',
                                 "%b %d '%y" => "%b %d '%y")
    ),
Simply add yours to that list as follows:

Code: Select all

    array(
        'var'           => 'date_format',
        'name'          => GENERAL_PLUGIN_DATEFORMAT . " (http://php.net/strftime)",
        'type'          => 'select',
        'default'       => DATE_FORMAT_ENTRY,
        'select_values' => array(DATE_FORMAT_ENTRY => DATE_FORMAT_ENTRY,
                                 '%a, %e. %B %Y' => '%a, %e. %B %Y',
                                 '%d-%m-%y' => '%d-%m-%y',
                                 '%m-%d-%y' => '%m-%d-%y',
                                 '%a %d-%m-%y' => '%a %d-%m-%y',
                                 '%a %m-%d-%y' => '%a %m-%d-%y',
                                 '%b %d' => '%b %d',
                                 "%b %d '%y" => "%b %d '%y",
                                 "%A, %e %B %Y" =>"%A, %e %B %Y")
    ),
You will need to repeat this modification for future s9y upgrades unless you have copied the bulletproof files to your own unique template folder.
=Don=
Post Reply