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

  • Mood:
  • Music:

Mmm. Fancy. <3

And now the fancier version, this one accepts url arguments. For example:
http://www.livejournal.com/users/zzyzx/402864.html?.tz=7
http://www.livejournal.com/users/zzyzx/402864.html?.tz=-9
http://www.livejournal.com/users/zzyzx/402864.html?.tz=-0327
http://www.livejournal.com/users/zzyzx/402864.html?.tz=0666

This code replaces the code in step 3 of my previous entry, if you want to allow the user to choose the timezone comments are displayed in, as well.


####################################################################
#GMT -- Timezone fix
####################################################################

	var Page p = get_page();

	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)?
	
	var int user_tz_min = $timezone_min;
	var int user_tz_neg = $tz_neg;
	var string user_tz = $p.args{"tz"};
	var string user_tz_fmt = "";
	var int user_tz_len = $user_tz->length();
	
	if ($user_tz_len>=1 and $user_tz_len<=5){
		if ($user_tz_len==1){
			$user_tz_fmt = zeropad($user_tz, 2);
			$user_tz_neg = 0;
		}
		if ($user_tz_len==2){
			if ($user_tz->starts_with("-")){
				$user_tz_neg = 1;
				$user_tz_fmt = zeropad($user_tz->substr(1, 1), 2);
			}
			if ($user_tz->starts_with("+")){
				$user_tz_neg = 0;
				$user_tz_fmt = zeropad($user_tz->substr(1, 1), 2);
			}
			if ($user_tz->starts_with("0") or $user_tz->starts_with("1")){
				$user_tz_neg = 0;
			}
		}
		if ($user_tz_len==3){
			if ($user_tz->starts_with("-")){
				$user_tz_neg = 1;
				$user_tz_fmt = $user_tz->substr(2, 2);
			}
			if ($user_tz->starts_with("+")){
				$user_tz_neg = 0;
				$user_tz_fmt = $user_tz->substr(2, 2);
			}
		}
		if ($user_tz_len==4){
			if ($user_tz->starts_with("-") or $user_tz->starts_with("+")){
				$user_tz_fmt = "";
			}
			if ($user_tz->starts_with("0") or $user_tz->starts_with("1")){
				$user_tz_neg = 0;
				$user_tz_fmt = $user_tz->substr(0, 2);
				$user_tz_min = int($user_tz->substr(2, 2));
			}
		}
		if ($user_tz_len==5){
			if ($user_tz->starts_with("-")){
				$user_tz_neg = 1;
				$user_tz_fmt = $user_tz->substr(1, 2);
				$user_tz_min = int($user_tz->substr(3, 2));
			}
			if ($user_tz->starts_with("+")){
				$user_tz_neg = 0;
				$user_tz_fmt = $user_tz->substr(1, 2);
				$user_tz_min = int($user_tz->substr(3, 2));
			}
		}
	}
	
	var int int_user_tz_fmt = int($user_tz_fmt);
	var int extra_hours = 0;
	var int extra_minutes =0;
	
	if ($user_tz_min >= 60){
		$extra_hours = 1;
		$user_tz_min = $user_tz_min % 60;
		$int_user_tz_fmt = $int_user_tz_fmt + $extra_hours;
	}
	
	if ($int_user_tz_fmt <= 12 and $int_user_tz_fmt >= 0 and $p.args{"tz"} != ""){
		$timezone = $int_user_tz_fmt;
		$tz_neg = $user_tz_neg;
		if ($user_tz_min != 0 and $user_tz_min <= 59 and $user_tz_min > 0){
			$timezone_min = $user_tz_min;
		}else{
			$timezone_min = 0;
		}
	}
	
	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;
	}

	if ($tz_hour < 00){
		$tz_hour = $tz_hour + 24;
		$tz_day = $tz_day - 1;
	}

	if ($tz_day > $month_days){
		$tz_day = $tz_day - $month_days;
		$tz_mon = $tz_mon + 1;
		$day_num = $day_num + 1;
	}

	if ($tz_day <= 00){
		$tz_day = $tz_day + $prev_month_days;
		$tz_mon = $tz_mon - 1;
		$day_num = $day_num - 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 = "Sunday";
	}
	if ($day_num == 2){
		$comment_dayname = "Monday";
	}
	if ($day_num == 3){
		$comment_dayname = "Tuesday";
	}
	if ($day_num == 4){
		$comment_dayname = "Wednesday";
	}
	if ($day_num == 5){
		$comment_dayname = "Thursday";
	}
	if ($day_num == 6){
		$comment_dayname = "Friday";
	}
	if ($day_num == 7){
		$comment_dayname = "Saturday";
	}

	var string comment_shortday = $comment_dayname->substr(0, 3);

	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 comment_shortmon = $comment_monthname->substr(0, 3);

	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+", "+$comment_monthname+", "+$str_day+$ordinal+", "+$str_year;



	#########
	#Available formats:
	#$str_yy_year = two-digit year (99, 00, 01)
	#$str_year = four-digit year (1999, 2000, 2001)
	#$str_mon = month number (9, 10, 11)
	#$str_day = day number (9, 10, 11)
	#$str_padmon = month number with leading zero (09, 10, 11)
	#$str_padday = day number with leading zero (09, 10, 11)
	#$comment_dayname = day name (Monday, Tuesday, Wednesday)
	#$comment_shortday = 3 letter day abbreviation (Mon, Tue, Wed)
	#$comment_monthname = full month name (January, February, March)
	#$comment_shortmon = 3 letter mon abbreviation (Jan, Feb, March)
	#$ordinal = day ordinal (st, nd, rd) (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
####################################################################</code>


I'll color it later. Maybe. >.> :P Now it's colored and everything!
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments