⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 2 页
字号:
}	/* intervalne() *//* *		intervallt		- returns TRUE, iff interval i1 is less than interval i2 *		Check length of intervals. */boolintervallt(TimeInterval i1, TimeInterval i2){	AbsoluteTime t10,				t11,				t20,				t21;	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return FALSE;			/* invalid interval */	t10 = i1->data[0];	t11 = i1->data[1];	t20 = i2->data[0];	t21 = i2->data[1];	if ((t10 == INVALID_ABSTIME) || (t20 == INVALID_ABSTIME)		|| (t20 == INVALID_ABSTIME) || (t21 == INVALID_ABSTIME))		return FALSE;	if (t10 == CURRENT_ABSTIME)		t10 = GetCurrentTransactionStartTime();	if (t11 == CURRENT_ABSTIME)		t11 = GetCurrentTransactionStartTime();	if (t20 == CURRENT_ABSTIME)		t20 = GetCurrentTransactionStartTime();	if (t21 == CURRENT_ABSTIME)		t21 = GetCurrentTransactionStartTime();	return (t11 - t10) < (t21 - t20);}	/* intervallt() *//* *		intervalle		- returns TRUE, iff interval i1 is less than or equal to interval i2 *		Check length of intervals. */boolintervalle(TimeInterval i1, TimeInterval i2){	AbsoluteTime t10,				t11,				t20,				t21;	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return FALSE;			/* invalid interval */	t10 = i1->data[0];	t11 = i1->data[1];	t20 = i2->data[0];	t21 = i2->data[1];	if ((t10 == INVALID_ABSTIME) || (t20 == INVALID_ABSTIME)		|| (t20 == INVALID_ABSTIME) || (t21 == INVALID_ABSTIME))		return FALSE;	if (t10 == CURRENT_ABSTIME)		t10 = GetCurrentTransactionStartTime();	if (t11 == CURRENT_ABSTIME)		t11 = GetCurrentTransactionStartTime();	if (t20 == CURRENT_ABSTIME)		t20 = GetCurrentTransactionStartTime();	if (t21 == CURRENT_ABSTIME)		t21 = GetCurrentTransactionStartTime();	return (t11 - t10) <= (t21 - t20);}	/* intervalle() *//* *		intervalgt		- returns TRUE, iff interval i1 is less than interval i2 *		Check length of intervals. */boolintervalgt(TimeInterval i1, TimeInterval i2){	AbsoluteTime t10,				t11,				t20,				t21;	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return FALSE;			/* invalid interval */	t10 = i1->data[0];	t11 = i1->data[1];	t20 = i2->data[0];	t21 = i2->data[1];	if ((t10 == INVALID_ABSTIME) || (t20 == INVALID_ABSTIME)		|| (t20 == INVALID_ABSTIME) || (t21 == INVALID_ABSTIME))		return FALSE;	if (t10 == CURRENT_ABSTIME)		t10 = GetCurrentTransactionStartTime();	if (t11 == CURRENT_ABSTIME)		t11 = GetCurrentTransactionStartTime();	if (t20 == CURRENT_ABSTIME)		t20 = GetCurrentTransactionStartTime();	if (t21 == CURRENT_ABSTIME)		t21 = GetCurrentTransactionStartTime();	return (t11 - t10) > (t21 - t20);}	/* intervalgt() *//* *		intervalge		- returns TRUE, iff interval i1 is less than or equal to interval i2 *		Check length of intervals. */boolintervalge(TimeInterval i1, TimeInterval i2){	AbsoluteTime t10,				t11,				t20,				t21;	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return FALSE;			/* invalid interval */	t10 = i1->data[0];	t11 = i1->data[1];	t20 = i2->data[0];	t21 = i2->data[1];	if ((t10 == INVALID_ABSTIME) || (t20 == INVALID_ABSTIME)		|| (t20 == INVALID_ABSTIME) || (t21 == INVALID_ABSTIME))		return FALSE;	if (t10 == CURRENT_ABSTIME)		t10 = GetCurrentTransactionStartTime();	if (t11 == CURRENT_ABSTIME)		t11 = GetCurrentTransactionStartTime();	if (t20 == CURRENT_ABSTIME)		t20 = GetCurrentTransactionStartTime();	if (t21 == CURRENT_ABSTIME)		t21 = GetCurrentTransactionStartTime();	return (t11 - t10) >= (t21 - t20);}	/* intervalge() *//* *		intervalleneq	- returns 1, iff length of interval i is equal to *								reltime t */boolintervalleneq(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt == t;}/* *		intervallenne	- returns 1, iff length of interval i is not equal *								to reltime t */boolintervallenne(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt != t;}/* *		intervallenlt	- returns 1, iff length of interval i is less than *								reltime t */boolintervallenlt(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt < t;}/* *		intervallengt	- returns 1, iff length of interval i is greater than *								reltime t */boolintervallengt(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt > t;}/* *		intervallenle	- returns 1, iff length of interval i is less or equal *									than reltime t */boolintervallenle(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt <= t;}/* *		intervallenge	- returns 1, iff length of interval i is greater or *								equal than reltime t */boolintervallenge(TimeInterval i, RelativeTime t){	RelativeTime rt;	if ((i->status == T_INTERVAL_INVAL) || (t == INVALID_RELTIME))		return 0;	rt = intervalrel(i);	return rt != INVALID_RELTIME && rt >= t;}/* *		intervalct		- returns 1, iff interval i1 contains interval i2 */boolintervalct(TimeInterval i1, TimeInterval i2){	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return 0;	return (abstimele(i1->data[0], i2->data[0]) &&			abstimege(i1->data[1], i2->data[1]));}/* *		intervalov		- returns 1, iff interval i1 (partially) overlaps i2 */boolintervalov(TimeInterval i1, TimeInterval i2){	if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)		return 0;	return (!(abstimelt(i1->data[1], i2->data[0]) ||			  abstimegt(i1->data[0], i2->data[1])));}/* *		intervalstart	- returns  the start of interval i */AbsoluteTimeintervalstart(TimeInterval i){	if (i->status == T_INTERVAL_INVAL)		return INVALID_ABSTIME;	return i->data[0];}/* *		intervalend		- returns  the end of interval i */AbsoluteTimeintervalend(TimeInterval i){	if (i->status == T_INTERVAL_INVAL)		return INVALID_ABSTIME;	return i->data[1];}/***************************************************************************** *	 PRIVATE ROUTINES														 * *****************************************************************************/#ifdef NOT_USED/* *		isreltime		- returns 1, iff datestring is of type reltime *								  2, iff datestring is 'invalid time' identifier *								  0, iff datestring contains a syntax error *		VALID time	less or equal +/-  `@ 68 years' * */intisreltime(char *str){	struct tm	tt,			   *tm = &tt;	double		fsec;	int			dtype;	char	   *field[MAXDATEFIELDS];	int			nf,				ftype[MAXDATEFIELDS];	char		lowstr[MAXDATELEN + 1];	if (!PointerIsValid(str))		return 0;	if (strlen(str) > MAXDATELEN)		return 0;	if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)		|| (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0))		return 0;	switch (dtype)	{		case (DTK_DELTA):			return (abs(tm->tm_year) <= 68) ? 1 : 0;			break;		case (DTK_INVALID):			return 2;			break;		default:			return 0;			break;	}	return 0;}	/* isreltime() */#endif#ifdef NOT_USEDintdummyfunc(){	char	   *p;	char		c;	int			i;	char		unit[UNITMAXLEN];	char		direction[DIRMAXLEN];	int			localSign;	int			localUnitNumber;	long		localQuantity;	if (!PointerIsValid(sign))		sign = &localSign;	if (!PointerIsValid(unitnr))		unitnr = &localUnitNumber;	if (!PointerIsValid(quantity))		quantity = &localQuantity;	unit[0] = '\0';	direction[0] = '\0';	p = timestring;	/* skip leading blanks */	while ((c = *p) != '\0')	{		if (c != ' ')			break;		p++;	}	/* Test whether 'invalid time' identifier or not */	if (!strncmp(INVALID_RELTIME_STR, p, strlen(INVALID_RELTIME_STR) + 1))		return 2;				/* correct 'invalid time' identifier found */	/* handle label of relative time */	if (c != RELTIME_LABEL)		return 0;				/* syntax error */	c = *++p;	if (c != ' ')		return 0;				/* syntax error */	p++;	/* handle the quantity */	*quantity = 0;	for (;;)	{		c = *p;		if (isdigit(c))		{			*quantity = *quantity * 10 + (c - '0');			p++;		}		else		{			if (c == ' ')				break;			/* correct quantity found */			else				return 0;		/* syntax error */		}	}	/* handle unit */	p++;	i = 0;	for (;;)	{		c = *p;		if (c >= 'a' && c <= 'z' && i <= (UNITMAXLEN - 1))		{			unit[i] = c;			p++;			i++;		}		else		{			if ((c == ' ' || c == '\0')				&& correct_unit(unit, unitnr))				break;			/* correct unit found */			else				return 0;		/* syntax error */		}	}	/* handle optional direction */	if (c == ' ')		p++;	i = 0;	*sign = 1;	for (;;)	{		c = *p;		if (c >= 'a' && c <= 'z' && i <= (DIRMAXLEN - 1))		{			direction[i] = c;			p++;			i++;		}		else		{			if ((c == ' ' || c == '\0') && i == 0)			{				*sign = 1;				break;			/* no direction specified */			}			if ((c == ' ' || c == '\0') && i != 0)			{				direction[i] = '\0';				correct_dir(direction, sign);				break;			/* correct direction found */			}			else				return 0;		/* syntax error */		}	}	return 1;}/* *		correct_unit	- returns 1, iff unit is a correct unit description * *		output parameter: *				unptr: points to an integer which is the appropriate unit number *					   (see function isreltime()) */static intcorrect_unit(char *unit, int *unptr){	int			j = 0;	while (j < NUNITS)	{		if (strncmp(unit, unit_tab[j], strlen(unit_tab[j])) == 0)		{			*unptr = j;			return 1;		}		j++;	}	return 0;					/* invalid unit descriptor */}/* *		correct_dir		- returns 1, iff direction is a correct identifier * *		output parameter: *				signptr: points to -1 if dir corresponds to past tense *						 else  to 1 */static intcorrect_dir(char *direction, int *signptr){	*signptr = 1;	if (strncmp(RELTIME_PAST, direction, strlen(RELTIME_PAST) + 1) == 0)	{		*signptr = -1;		return 1;	}	else		return 0;				/* invalid direction descriptor */}#endif/* *		istinterval		- returns 1, iff i_string is a valid interval descr. *								  0, iff i_string is NOT a valid interval desc. *								  2, iff any time is INVALID_ABSTIME * *		output parameter: *				i_start, i_end: interval margins * *		Time interval: *		`[' {` '} `'' <AbsTime> `'' {` '} `'' <AbsTime> `'' {` '} `]' * *		OR	`Undefined Range'	(see also INVALID_INTERVAL_STR) * *		where <AbsTime> satisfies the syntax of absolute time. * *		e.g.  [  '  Jan 18 1902'   'Jan 1 00:00:00 1970'] */static intistinterval(char *i_string,			AbsoluteTime *i_start,			AbsoluteTime *i_end){	char	   *p,			   *p1;	char		c;	p = i_string;	/* skip leading blanks up to '[' */	while ((c = *p) != '\0')	{		if (IsSpace(c))			p++;		else if (c != '[')			return 0;			/* syntax error */		else			break;	}	p++;	/* skip leading blanks up to "'" */	while ((c = *p) != '\0')	{		if (IsSpace(c))			p++;		else if (c != '"')			return 0;			/* syntax error */		else			break;	}	p++;	if (strncmp(INVALID_INTERVAL_STR, p, strlen(INVALID_INTERVAL_STR)) == 0)		return 0;				/* undefined range, handled like a syntax								 * err. */	/* search for the end of the first date and change it to a NULL */	p1 = p;	while ((c = *p1) != '\0')	{		if (c == '"')		{			*p1 = '\0';			break;		}		p1++;	}	/* get the first date */	*i_start = nabstimein(p);	/* first absolute date */	/* rechange NULL at the end of the first date to a "'" */	*p1 = '"';	p = ++p1;	/* skip blanks up to "'", beginning of second date */	while ((c = *p) != '\0')	{		if (IsSpace(c))			p++;		else if (c != '"')			return 0;			/* syntax error */		else			break;	}	p++;	/* search for the end of the second date and change it to a NULL */	p1 = p;	while ((c = *p1) != '\0')	{		if (c == '"')		{			*p1 = '\0';			break;		}		p1++;	}	/* get the second date */	*i_end = nabstimein(p);		/* second absolute date */	/* rechange NULL at the end of the first date to a ''' */	*p1 = '"';	p = ++p1;	/* skip blanks up to ']' */	while ((c = *p) != '\0')	{		if (IsSpace(c))			p++;		else if (c != ']')			return 0;			/* syntax error */		else			break;	}	p++;	c = *p;	if (c != '\0')		return 0;				/* syntax error */	/* it seems to be a valid interval */	return 1;}/***************************************************************************** * *****************************************************************************//* * timeofday - *	   returns the current time as a text. similar to timenow() but returns *	   seconds with more precision (up to microsecs). (I need this to compare *	   the Wisconsin benchmark with Illustra whose TimeNow() shows current *	   time with precision up to microsecs.)			  - ay 3/95 */text *timeofday(void){	struct timeval tp;	struct timezone tpz;	char		templ[500];	char		buf[500];	text	   *tm;	int			len = 0;	gettimeofday(&tp, &tpz);	strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%d %Y %Z",			 localtime((time_t *) &tp.tv_sec));	sprintf(buf, templ, tp.tv_usec);	len = VARHDRSZ + strlen(buf);	tm = (text *) palloc(len);	VARSIZE(tm) = len;	strncpy(VARDATA(tm), buf, strlen(buf));	return tm;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -