-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtimegetutc.c
90 lines (78 loc) · 2.45 KB
/
timegetutc.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <edidentifier.h>
__CIDENT_RCSID(gr_timegetutc_c,"$Id: timegetutc.c,v 1.11 2024/07/19 05:05:03 cvsuser Exp $")
/* -*- mode: c; indent-width: 4; -*- */
/* $Id: timegetutc.c,v 1.11 2024/07/19 05:05:03 cvsuser Exp $
* Portable (somewhat) method to determine GMT offset.
*
*
* Copyright (c) 1998 - 2024, Adam Young.
* All rights reserved.
*
* This file is part of the GRIEF Editor.
*
* The GRIEF Editor is free software: you can redistribute it
* and/or modify it under the terms of the GRIEF Editor License.
*
* Redistributions of source code must retain the above copyright
* notice, and must be distributed with the license document above.
*
* Redistributions in binary form must reproduce the above copyright
* notice, and must include the license document above in
* the documentation and/or other materials provided with the
* distribution.
*
* The GRIEF Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License for more details.
* ==end==
*/
#if defined(HAVE_CONFIG_H)
#include <config.h>
#endif
#include <edthreads.h>
#include <libtime.h>
time_t
timeutcoffsetx(const int year, const int mon, const int mday, const int hour, const int min)
{
/* #if defined(HAVE_MKTIME) || \
* defined(_MSC_VER) || defined(__WATCOMC__) || defined(unix) || defined(__unix__)
*/
struct tm local_tm = {0}, utc_tm = {0}, *utc_tmptr;
time_t local_t, utc_t, utcOffset = 0;
local_tm.tm_year = year;
local_tm.tm_mon = mon - 1;
local_tm.tm_mday = mday;
local_tm.tm_hour = hour;
local_tm.tm_min = min;
local_tm.tm_isdst = -1;
local_t = mktime(&local_tm);
if (local_t != (time_t) -1) {
#if defined(HAVE_GMTIME_R)
utc_tmptr = gmtime_r(&local_t, &local_tm);
#else
utc_tmptr = gmtime(&local_t);
#endif
utc_tm.tm_year = utc_tmptr->tm_year;
utc_tm.tm_mon = utc_tmptr->tm_mon;
utc_tm.tm_mday = utc_tmptr->tm_mday;
utc_tm.tm_hour = utc_tmptr->tm_hour;
utc_tm.tm_min = utc_tmptr->tm_min;
utc_tm.tm_isdst = -1;
utc_t = mktime(&utc_tm);
if (utc_t != (time_t) -1) {
utcOffset = (local_t - utc_t);
}
}
return utcOffset;
/* #else
* return -1;
* #endif
*/
}
time_t
timeutcoffset(const int mon, const int mday)
{
return (timeutcoffsetx(2000, mon, mday, 12, 0));
}
/*end*/