howto_user (howto_user) wrote in s2howto,
howto_user
howto_user
s2howto

[paidaccount] Adding time zone support to custom layouts

Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

The LiveJournal core layer provides time_display() method that specifies the time zone to use for the comment times. All the system layouts use this method in order to display the comment times in your local time zone if you have set one. If you are using a custom layout, however, you will need to modify its code, if the comments are shown in a different time zone.

You will need to find the code of your custom layout that specifies the way the comments or more specifically the date and time of the comments are printed. Usually this code may be found in EntryPage::print_comment(Comment c) or EntryPage::print_comment_partial(Comment c) functions, but it may differ. You will need to modify the code to use the time_display() method like in the following line:

print $c->time_display();

where $c is the Comment class variable used in your layout.

If you would like to specify different date and time formats, you can use another form of time_display() method, with the additional code in the parentheses. For example, the following code will change the date format to "Tue, Feb. 5th (1980)" and leave the time format default.

print $c->time_display("%%da%%, %%mon%%. %%dayord%% (%%yyyy%%)", "");

Please see the Date and Time Formats tutorial for further details.

Contributed by camomiletea.

Tags: paid accounts only, timezone support
Subscribe
Comments for this post were disabled by the author