1 頁 (共 1 頁)

[問題] 生日外掛中的user_birthday欄位代表的意義是什麼?

發表於 : 2005-11-25 10:36
一平
問題外掛:會員生日Birthday Mod1.5.7
參考連結:
使用版本:phpBB 2.17
網站位置:http://npb.club.tw
狀況描述:

小弟有安裝生日外掛,想自己寫程式把生日外掛中的會員生日資料拿出來使用。在phpbb_users這個資料表裡,user_birthday欄位都是一個四位數的數字。

以小弟的資料為例,1978年4月15日生,出現的數字是3026。

我想知道的是資料庫中這些代表生日的四位數字,要怎麼還原回一般人看的懂的月、日呢?是不是有一個函數在?

Re: [問題] 生日外掛中的user_birthday欄位代表的意義是什麼?

發表於 : 2005-11-25 17:34
心靈捕手
一平 寫:小弟有安裝生日外掛,想自己寫程式把生日外掛中的會員生日資料拿出來使用。在phpbb_users這個資料表裡,user_birthday欄位都是一個四位數的數字。

以小弟的資料為例,1978年4月15日生,出現的數字是3026。

我想知道的是資料庫中這些代表生日的四位數字,要怎麼還原回一般人看的懂的月、日呢?是不是有一個函數在?
建議您:
補齊" 發問格式":
http://phpbb-tw.net/phpbb/viewtopic.php?t=16161

ps.
移動到" 非官方外掛討論" 版面.

發表於 : 2005-11-26 23:49
~倉木麻衣~
在安裝文件裡就有作者自訂的轉換函式了
查一下安裝文件裡要在functions.php裡新增的那二個函式吧

發表於 : 2005-11-27 12:56
一平
以下倉木大大所說的,生日模組在functions.php裡新增的那二個函式,但小弟實在愚鈍,看不出來到底為什麼他能把生日至少19780415這八個數字濃縮轉化成3026,到底是什麼意思啊,可否有高人可指點一下

代碼: 選擇全部

#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php

#
#-----[ FIND ]------------------------------------------------
#
?>

#
#-----[ BEFORE, ADD ]-----------------------------------------
#

// Add function mkrealdate for Birthday MOD
// the originate php "mktime()", does not work proberly on all OS, especially when going back in time
// before year 1970 (year 0), this function "mkrealtime()", has a mutch larger valid date range,
// from 1901 - 2099. it returns a "like" UNIX timestamp divided by 86400, so
// calculation from the originate php date and mktime is easy.
// mkrealdate, returns the number of day (with sign) from 1.1.1970.

function mkrealdate($day,$month,$birth_year)
{
	// range check months
	if ($month<1 || $month>12) return "error";
	// range check days
	switch ($month)
	{
		case 1: if ($day>31) return "error";break;
		case 2: if ($day>29) return "error";
			$epoch=$epoch+31;break;
		case 3: if ($day>31) return "error";
			$epoch=$epoch+59;break;
		case 4: if ($day>30) return "error" ;
			$epoch=$epoch+90;break;
		case 5: if ($day>31) return "error";
			$epoch=$epoch+120;break;
		case 6: if ($day>30) return "error";
			$epoch=$epoch+151;break;
		case 7: if ($day>31) return "error";
			$epoch=$epoch+181;break;
		case 8: if ($day>31) return "error";
			$epoch=$epoch+212;break;
		case 9: if ($day>30) return "error";
			$epoch=$epoch+243;break;
		case 10: if ($day>31) return "error";
			$epoch=$epoch+273;break;
		case 11: if ($day>30) return "error";
			$epoch=$epoch+304;break;
		case 12: if ($day>31) return "error";
			$epoch=$epoch+334;break;
	}
	$epoch=$epoch+$day;
	$epoch_Y=sqrt(($birth_year-1970)*($birth_year-1970));
	$leapyear=round((($epoch_Y+2) / 4)-.5);
	if (($epoch_Y+2)%4==0)
	{// curent year is leapyear
		$leapyear--;
		if ($birth_year >1970 && $month>=3) $epoch=$epoch+1;
		if ($birth_year <1970 && $month<3) $epoch=$epoch-1;
	} else if ($month==2 && $day>28) return "error";//only 28 days in feb.
	//year
	if ($birth_year>1970)
		$epoch=$epoch+$epoch_Y*365-1+$leapyear;
	else
		$epoch=$epoch-$epoch_Y*365-1-$leapyear;
	return $epoch;
}

// Add function realdate for Birthday MOD
// the originate php "date()", does not work proberly on all OS, especially when going back in time
// before year 1970 (year 0), this function "realdate()", has a mutch larger valid date range,
// from 1901 - 2099. it returns a "like" UNIX date format (only date, related letters may be used, due to the fact that
// the given date value should already be divided by 86400 - leaving no time information left)
// a input like a UNIX timestamp divided by 86400 is expected, so
// calculation from the originate php date and mktime is easy.
// e.g. realdate ("m d Y", 3) returns the string "1 3 1970"

// UNIX users should replace this function with the below code, since this should be faster
//
//function realdate($date_syntax="Ymd",$date=0) 
//{ return create_date($date_syntax,$date*86400+1,0); }

function realdate($date_syntax="Ymd",$date=0)
{
	global $lang;
	$i=2;
	if ($date>=0)
	{
	 	return create_date($date_syntax,$date*86400+1,0);
	} else
	{
		$year= -(date%1461);
		$days = $date + $year*1461;
		while ($days<0)
		{
			$year--;
			$days+=365;
			if ($i++==3)
			{
				$i=0;
				$days++;
			}
		}
	}
	$leap_year = ($i==0) ? TRUE : FALSE;
	$months_array = ($i==0) ?
		array (0,31,60,91,121,152,182,213,244,274,305,335,366) :
		array (0,31,59,90,120,151,181,212,243,273,304,334,365);
	for ($month=1;$month<12;$month++)
	{
		if ($days<$months_array[$month]) break;
	}

	$day=$days-$months_array[$month-1]+1;
	//you may gain speed performance by remove som of the below entry's if they are not needed/used
	return strtr ($date_syntax, array(
		'a' => '',
		'A' => '',
		'\\\d' => 'd',
		'd' => ($day>9) ? $day : '0'.$day,
		'\\\D' => 'D',
		'D' => $lang['day_short'][($date-3)%7],
		'\\\F' => 'F',
		'F' => $lang['month_long'][$month-1],
		'g' => '',
		'G' => '',
		'H' => '',
		'h' => '',
		'i' => '',
		'I' => '',
		'\\\j' => 'j',
		'j' => $day,
		'\\\l' => 'l',
		'l' => $lang['day_long'][($date-3)%7],
		'\\\L' => 'L',
		'L' => $leap_year,
		'\\\m' => 'm',
		'm' => ($month>9) ? $month : '0'.$month,
		'\\\M' => 'M',
		'M' => $lang['month_short'][$month-1],
		'\\
' => 'n',
		'n' => $month,
		'O' => '',
		's' => '',
		'S' => '',
		'\\\t' => 't',
		't' => $months_array[$month]-$months_array[$month-1],
		'w' => '',
		'\\\y' => 'y',
		'y' => ($year>29) ? $year-30 : $year+70,
		'\\\Y' => 'Y',
		'Y' => $year+1970,
		'\\\z' => 'z',
		'z' => $days,
		'\\\W' => '',
		'W' => '') );
}
// End add - Birthday MOD

發表於 : 2005-11-27 18:53
心靈捕手
To 一平:

這個欄位的數字, 主要是依照您的生日, 減掉 1970-01-01, 所得的數值.

例如:
若生日是 1970-01-01 則其值為 0
若生日是 1971-01-01 則其值為 365
...
若生日是 1978-04-14 則其值為 3025
若生日是 1978-04-15 則其值為 3026

當然, 若是在 1970-01-01 以前出生者, 則其值為負數\r
像我, 該欄位的值是 -2086 :mrgreen: