Zzyzx Wolfe (zzyzx) wrote in component_help,
Zzyzx Wolfe
zzyzx
component_help

  • Mood:
  • Music:

Comments in Your Timezone!

Want to change that pesky GMT timezone on your comments page?

  1. Apply the Customising the layout of your Comment Headers tutorial.


  2. Find the line which reads:
    function EntryPage::print_comment(Comment comment) {


  3. On the line beneath it, paste the following, configuring as you see fit:

  4. #################################################################### #GMT -- Timezone fix ####################################################################
    var string comment_date = $comment.time->date_format(); var string comment_time = $comment.time->time_format(); var string comment_dayname = $comment.time->date_format("%%da%%"); var int comment_year = 0; var int comment_month = 0; var int comment_day = 0; var int comment_hour = 0; var int time_iso = 0; var int comment_min = 0; var int timezone = 07; #Offset from GMT in hours. (NO NEGATIVES!) If your offset from GMT is -0730, this value would be "07". var int timezone_min = 00; #Offset from GMT in minutes. If your offset from GMT is -0730, this value would be "30". var int tz_neg = 1; #Offset is negative = 1 (USA is = 1) or positive = 0 If your offset from GMT is -0730, this value would be "1". var int dst = 0; #Is your timezone currently observing DST (Daylight Saving Time)? (0 is No. 1 is Yes.) var string negpos = "+"; if ($tz_neg == 1){ $negpos = "-"; } if ($dst == 1){ $timezone = $timezone + 01; } if ($timezone < 00 or $timezone > 12){ $timezone = 00; } if ($timezone_min >= 60 or $timezone_min < 00){ $timezone_min = 00; } $comment_year = int($comment.time->date_format("%%yyyy%%")); $comment_month = int(0+$comment.time->date_format("%%mm%%")); $comment_day = int(0+$comment.time->date_format("%%dd%%")); $comment_hour = int(0+$comment.time->date_format("%%HH%%")); $comment_min = int(0+$comment.time->date_format("%%min%%")); var int tz_year = $comment_year; var int tz_hour = $comment_hour; var int tz_min = $comment_min; var int tz_day = $comment_day; var int tz_mon = $comment_month; var int prev_month_days = 30; var int feb_days = 28; var int day_num = 1; var int month_days = 31; var int year_days = 365; var int prev_year_days = 365; var int prev_year = $comment_year - 1; if ($comment_year % 4 == 0){ $year_days = 366; } if ($prev_year % 4 == 0){ $prev_year_days = 366; } if ($comment_month == 04 or $comment_month == 06 or $comment_month == 09 or $comment_month == 11){ $month_days = 30; $prev_month_days = 31; } if ($comment_year % 4 == 0){ $feb_days = 29; } if ($comment_month == 03){ $prev_month_days = $feb_days; } if ($comment_month == 02){ $month_days = $feb_days; } if ($tz_neg == 1){ $tz_hour = $comment_hour - $timezone; $tz_min = $tz_min - $timezone_min; }else{ $tz_hour = $comment_hour + $timezone; $tz_min = $tz_min + $timezone_min; } if ($comment_dayname == "Sun"){ $day_num = 1; } if ($comment_dayname == "Mon"){ $day_num = 2; } if ($comment_dayname == "Tue"){ $day_num = 3; } if ($comment_dayname == "Wed"){ $day_num = 4; } if ($comment_dayname == "Thu"){ $day_num = 5; } if ($comment_dayname == "Fri"){ $day_num = 6; } if ($comment_dayname == "Sat"){ $day_num = 7; } if ($tz_min >= 60){ $tz_min = $tz_min - 60; $tz_hour = $tz_hour + 1; } if ($tz_min < 00){ $tz_min = $tz_min + 60; $tz_hour = $tz_hour - 1; } if ($tz_hour >= 24){ $tz_hour = $tz_hour - 24; $tz_day = $tz_day + 1; $day_num = $day_num + 1; } if ($tz_hour < 00){ $tz_hour = $tz_hour + 24; $tz_day = $tz_day - 1; $day_num = $day_num - 1; } if ($tz_day > $month_days){ $tz_day = $tz_day - $month_days; $tz_mon = $tz_mon + 1; } if ($tz_day <= 00){ $tz_day = $tz_day + $prev_month_days; $tz_mon = $tz_mon - 1; } if ($tz_mon > 12){ $tz_mon = $tz_mon - 12; $tz_year = $tz_year + 1; } if ($tz_mon <= 0){ $tz_mon = $tz_mon + 12; $tz_year = $tz_year - 1; } if ($day_num <= 0){ $day_num = 7 + $day_num; } var string AMPM = "PM"; if ($tz_hour >= 00 and $tz_hour < 12){ $AMPM = "AM"; } var int tw_hour = $tz_hour; if ($AMPM == "PM"){ $tw_hour = $tw_hour - 12; } var int yy_year = $tz_year - 1900; if ($yy_year >= 100){ $yy_year = $yy_year - 100; } var string ordinal = "th"; if ($tz_day == 01 or $tz_day == 21 or $tz_day == 31){ $ordinal = "st"; } if ($tz_day == 02 or $tz_day == 22){ $ordinal = "nd"; } if ($tz_day == 03 or $tz_day == 23){ $ordinal = "rd"; } if ($day_num == 1){ $comment_dayname = "Sun"; } if ($day_num == 2){ $comment_dayname = "Mon"; } if ($day_num == 3){ $comment_dayname = "Tues"; } if ($day_num == 4){ $comment_dayname = "Wednes"; } if ($day_num == 5){ $comment_dayname = "Thurs"; } if ($day_num == 6){ $comment_dayname = "Fri"; } if ($day_num == 7){ $comment_dayname = "Satur"; } var string comment_monthname = "December"; if ($tz_mon == 01){ $comment_monthname = "January"; } if ($tz_mon == 02){ $comment_monthname = "February"; } if ($tz_mon == 03){ $comment_monthname = "March"; } if ($tz_mon == 04){ $comment_monthname = "April"; } if ($tz_mon == 05){ $comment_monthname = "May"; } if ($tz_mon == 06){ $comment_monthname = "June"; } if ($tz_mon == 07){ $comment_monthname = "July"; } if ($tz_mon == 08){ $comment_monthname = "August"; } if ($tz_mon == 09){ $comment_monthname = "September"; } if ($tz_mon == 10){ $comment_monthname = "October"; } if ($tz_mon == 11){ $comment_monthname = "November"; } var string str_yy_year = string($yy_year); var string str_year = string($tz_year); var string str_mon = string($tz_mon); var string str_day = string($tz_day); var string str_padmon = zeropad($str_mon, 2); var string str_padday = zeropad($str_day, 2); var string tz_date = $comment_dayname+"day, "+$comment_monthname+", "+$str_day+$ordinal+", "+$str_year;
    ######### #Available formats: #$str_yy_year = two-digit year #$str_year = four-digit year #$str_mon = month number #$str_day = day number #$str_padmon = month number with leading zero #$str_padday = day number with leading zero #$comment_dayname = day name without "-day" suffix #$comment_monthname = full month name #$ordinal = day ordinal st, nd, rd, etc (NO NUMBER!)
    var string str_hour = string($tw_hour); var string str_padhour = zeropad($str_hour, 2); var string str_milhour = string($tz_hour); var string str_padmilhour = zeropad($str_hour, 2); var string str_min = string($tz_min); var string str_padmin = zeropad($str_min, 2); var string str_timezone = string($timezone); var string str_timezone_min = string($timezone_min); var string str_offset = $negpos+zeropad($str_timezone, 2)+zeropad($str_timezone_min, 2); var string tz_time = $str_hour+":"+$str_padmin+" "+$AMPM+" ("+$str_offset+" GMT)";
    ######### #Available formats: #$str_hour = twelve hour #$str_padhour = twelve hour with leading zero #$str_milhour = 24 hour #$str_padmilhour = 24 hour with leading zero #$str_padmin = minutes with leading zero #$AMPM = AM or PM #$str_offset = prints current offset ####################################################################
    </li>

  5. Find the line which reads: <td colspan="2" align="left" style="white-space: nowrap"><strong>$date</strong> """; print $comment.time->date_format("long")+" - "+$comment.time->time_format(); """</td> and replace it with the following: <td colspan="2" align="left" style="white-space: nowrap"><strong>$date</strong> $tz_date - $tz_time</td>.


This code hasn't been fully tested for all sorts of things like leap-years and such, so if you notice any odd dates, please tell me!
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 13 comments