ex_awakened208: (Default)
♡ ([personal profile] ex_awakened208) wrote in [community profile] style_system2012-08-19 03:20 am

Replacing Day of Week Text With an Image

In a date format that includes the day of the week in it, does anyone know how to replace the name of the day of the week with an image. For example, if I wanted to replace the text "Sat" with this image: a circle with the text "Sat" on it

This is the custom format I'm using for the date on the journal in question. Applied through theme layer.

ninetydegrees: Art & Text: heart with aroace colors, "you are loved" (Default)

[personal profile] ninetydegrees 2012-08-19 03:19 pm (UTC)(link)
Wow! This brings back memories!
Here's the code:

set entry_date_format = "short";
set lang_fmt_date_short = "%%mm%%/%%dd%%/%%yy%%";

function Entry::time_display(string datefmt, string timefmt) : string {
    var Page p = get_page();

var string day = $.time->date_format("%%day%%");

var string{} dayimage =
{
    "Monday" => "Monday.jpg",
    "Tuesday" => "Tuesday.jpg",
    "Wednesday" => "Wednesday.jpg",
    "Thursday" => "Thursday.jpg",
    "Friday" => "Friday.jpg",
    "Saturday" => "http://i1231.photobucket.com/albums/ee518/venbunny/Help/sat.gif",
    "Sunday" => "Sunday.jpg",
};

    var bool linkify = ( $p.view == "recent" or $p.view == "entry" or $p.view == "reply" or $p.view == "day" );

    if ($datefmt == "") { $datefmt = $*entry_date_format; }

    if ($timefmt == "") {

        if (viewer_logged_in()) {
            if (viewer_is_owner()) {
                $timefmt = $*entry_time_format;
            } else {
                if ($this.timeformat24) {
                    $timefmt = "short_24";
                } else {
                    $timefmt = "short";
                }
            }
        } else {
            $timefmt = $*entry_time_format;
        }

    } else {
        $timefmt = "short";
    }

    var string ret;
    if ($datefmt != "none") { $ret = $ret + """<span class="date"><img src="$dayimage{$day}" />""" + $this.time->date_format($datefmt, $linkify) + "</span>"; }
    if ($datefmt != "none" and $timefmt != "none") { $ret = $ret + " "; }
    if ($timefmt != "none") { $ret = $ret + """<span class="time">""" + $this.time->time_format($timefmt) + "</span>"; }

    if ($ret != "") { $ret = """<span class="datetime">$ret</span>"""; }

    return $ret;
}

All credit goes to kentucka from s2flexisquares over on LJ.
Edited 2012-08-19 15:20 (UTC)