Flexible Squares: GMT in entries

Nov 10, 2008 00:05

Sometimes it's useful to know the exact time a post was made to LJ, especially on your flist. Here's a snippet of code to show the date & time in GMT that the server recorded when the post was made.

1. Make sure you have created a theme layer.

2. If you don't have a function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor) in your theme layer yet, go to the Flexible Squares source, find the function, and copy it to your theme layer.

3. Add the two segments of blue code below to your theme layer's print_entry function:

function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor)
{
"""""";
$e->print_linkbar();

# Userpic

var string userpic = "";
if ($*show_entry_userpic)
{
if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
{
if (defined $e.userpic)
{
$userpic = $userpic + """
";
}
}
elseif ($p.journal_type == "C" and $p.view == "recent")
{
if (defined $e.userpic)
{
$userpic = $userpic + """
""";
}
}
else
{
if (defined $e.userpic)
{
$userpic = $userpic + """

""";
}
}
}
print """

""";
if (($p.view == "recent" and $p.journal_type != "C" ) or $p.view == "day")
{
print """$userpic""";
}
else
{
if ($p.view == "recent" and $p.journal_type == "C" )
{
"""
""";
}
else
{
"""
""";
}
print """$userpic""";

# Poster

if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
{
var UserLite linkto;
$linkto = $e.poster;
#print "$e.poster.username";
"""
base_url() + "\">";
"$linkto.username
";
}
elseif ($p.journal_type == "C" and $p.view == "recent")
{
var UserLite linkto;
$linkto = $e.poster;
#print "$e.poster.username";
"""
base_url() + "\">";
"$linkto.username
";
}
if (($p.view == "friends" or $p.view == "entry" or $p.view == "reply") and $e.poster.username != $e.journal.username)
{
var UserLite linkto;
$linkto = $e.journal;
"""
[ base_url() + "\">";
"$linkto.username
]";
}
if ($p.view == "recent" and $p.journal_type == "C")
{
print "";
}
if ($p.view != "recent" and $p.view != "day")
{
print """""";
}
}

# Date, time, subject

# Show the system time in GMT
var DateTime gmt = $e.system_time;
var string gmtstr = "";
if ($p.view == "friends") {
$gmtstr = """ [""" + $gmt->date_format("%%mon%%. %%dayord%%") + " " + $gmt->time_format() + " GMT]";
}

var string time = "";
$time = $time + """ @ """;
$time = $time + $e.time->time_format("short");
var string date = "";
$date = $date + $e.time->date_format("long_day");
"""

""";
print $e.time->date_format("%%dd%% %%month%% %%yyyy%%");
"$time $gmtstr
";
"""

""";
if ($e.security != "")
{
$e.security_icon->print();
}
if ($p.view != "entry") {
""" $e.subject """;
}
else { print "$e.subject "; }
"""

""";

"""

""";

$e->print_text();
print " ";

# Currents

var string currents ="";
$e->print_metadata();

# Comments

"""

""";
if ($p.view != "entry" or $p.view != "reply")
{
$e.comments->print();
}
elseif ($e.comments.enabled)
{
$e.comments->print_postlink();
}
else
{
" ";
}
"""

""";
}
4. If you only want to show the system datetime in GMT on your Friends Page entries, hit Save & Compile and you're done! If you prefer to have the system datetime show on ALL entries in your journal, go on to step 5.

5. In the first segment of blue code that you added to the print_entry function, find and delete these two highlighted lines:

# Show the system time in GMT
var DateTime gmt = $e.system_time;
var string gmtstr = "";
if ($p.view == "friends") {
$gmtstr = """ [""" + $gmt->date_format("%%mon%%. %%dayord%%") + " " + $gmt->time_format() + " GMT]";
}Now hit Save & Compile and you're done!

layout:flexiblesquares, code:gmt

Previous post
Up