1/* u_getutc.c
2 *
3 * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
4 * All rights reserved.
5 *
6 */
7
8#include "syshdrs.h"
9#ifdef PRAGMA_HDRSTOP
10#	pragma hdrstop
11#endif
12
13/* Cheezy, but somewhat portable way to get GMT offset. */
14time_t
15GetUTCOffset2(const int year, const int mon, const int mday, const int hour, const int min)
16{
17#ifdef HAVE_MKTIME
18	struct tm local_tm, utc_tm, *utc_tmptr;
19	time_t local_t, utc_t, utcOffset;
20
21	ZERO(local_tm);
22	ZERO(utc_tm);
23	utcOffset = 0;
24
25	local_tm.tm_year = year;
26	local_tm.tm_mon = mon - 1;
27	local_tm.tm_mday = mday;
28	local_tm.tm_hour = hour;
29	local_tm.tm_min = min;
30	local_tm.tm_isdst = -1;
31	local_t = mktime(&local_tm);
32
33	if (local_t != (time_t) -1) {
34		utc_tmptr = Gmtime(local_t, &local_tm);
35		utc_tm.tm_year = utc_tmptr->tm_year;
36		utc_tm.tm_mon = utc_tmptr->tm_mon;
37		utc_tm.tm_mday = utc_tmptr->tm_mday;
38		utc_tm.tm_hour = utc_tmptr->tm_hour;
39		utc_tm.tm_min = utc_tmptr->tm_min;
40		utc_tm.tm_isdst = -1;
41		utc_t = mktime(&utc_tm);
42
43		if (utc_t != (time_t) -1)
44			utcOffset = (local_t - utc_t);
45	}
46	return (utcOffset);
47#else
48	return ((time_t) -1);
49#endif	/* HAVE_MKTIME */
50}	/* GetUTCOffset2 */
51
52
53
54
55time_t
56GetUTCOffset(const int mon, const int mday)
57{
58	return (GetUTCOffset2(2000, mon, mday, 12, 0));
59}	/* GetUTCOffset */
60