Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source libSC Time tm tmtime.c
Document Actions

tmtime.c

by Michael L Powell last modified 2007-01-26 03:24

Click here to get the file

Size 2.0 kB - File type text/plain

File contents

/*ident	"@(#)Time:tm/tmtime.c	3.1" */
/******************************************************************************
*
* C++ Standard Components, Release 3.0.
*
* Copyright (c) 1991, 1992 AT&T and Unix System Laboratories, Inc.
* Copyright (c) 1988, 1989, 1990 AT&T.  All Rights Reserved.
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and Unix System
* Laboratories, Inc.  The copyright notice above does not evidence
* any actual or intended publication of such source code.
*
******************************************************************************/

#include <Timelib.h>
#include <tm.h>

/*
 * convert struct tm to time_t
 *
 * if west==TM_LOCALZONE then the local timezone is used
 * otherwise west is the number of minutes west
 * of GMT with DST taken into account
 */

time_t tmtime_ATTLC(register struct tm* tp, int west) {
	register time_t		clock;
	register struct tl*	lp;
	int			n;
	int			sec;
	time_t			now;

	tmset();
/*
 * The following equation is correct for the years 1898-2100.
 *
 * ( It is also correct for the interval [1802,1897] except for
 *   y such that (y-1805)%4==0. )
 */
	clock = (tp->tm_year * (4 * 365 + 1) - 69) / 4 - 70 * 365;
	if ((n = tp->tm_mon) > 11) n = 11;
	if (n > 1 && is_leap(1900+tp->tm_year)) clock++;
	clock += tm_msum_ATTLC[n] + tp->tm_mday - 1;
	clock *= 24;
	clock += tp->tm_hour;
	clock *= 60;
	clock += tp->tm_min;
	clock *= 60;
	clock += sec = tp->tm_sec;
	if (!(tm_flags_ATTLC & TM_UTC))
	{
		/*
		 * time zone adjustments
		 */

		if (west == TM_LOCALZONE)
		{
			clock += tm_local_ATTLC->west * 60;
			now = clock;
			if (tmmake_ATTLC(&now)->tm_isdst) clock += tm_local_ATTLC->dst * 60;
		}
		else clock += west * 60;
	}
	if (tm_flags_ATTLC & TM_LEAP)
	{
		/*
		 * leap second adjustments
		 */

		if (clock > 0)
		{
			for (lp = &tm_leap_ATTLC[0]; clock < lp->time - (lp+1)->total; lp++);
			clock += lp->total;
			n = lp->total - (lp+1)->total;
			if (clock <= (lp->time + n) && (n > 0 && sec > 59 || n < 0 && sec > (59 + n) && sec <= 59)) clock -= n;
		}
	}
	return(clock);
}
« March 2024 »
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: