Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
timezone.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include "wlib/xtime.h"
20#include "timezone.h"
21
22void GetTimezoneInfo(const char * &timezone_str, int &timezone_offset) {
23 timezone_str = "Unknown Timezone";
24 timezone_offset = 0;
25#ifdef _WINDOWS
26 struct _timeb wintime;
27 _ftime(&wintime);
28
29 if (wintime.dstflag) {
30 // Daylight savings time
31 if (_daylight) {
32 timezone_str = _tzname[1];
33 }
34 } else {
35 timezone_str = _tzname[0];
36 }
37 timezone_offset = wintime.timezone * 60; // its in minutes...
38
39#endif
40#ifndef _WINDOWS
41 struct timeval unixtime;
42 struct timezone unixtzone;
43 gettimeofday(&unixtime,&unixtzone);
44
45 struct tm unixtm;
46 localtime_r(&unixtime.tv_sec, &unixtm);
47
48 if (unixtm.tm_isdst) {
49 // Daylight savings time
50 if (daylight) timezone_str = tzname[1];
51 timezone_offset = altzone;
52 } else {
53 timezone_str = tzname[0];
54 timezone_offset = timezone;
55 }
56#endif
57}
58
59const char * TimezoneString(void) {
60 const char *timezone_str;
61 int timezone_offset;
62 GetTimezoneInfo(timezone_str, timezone_offset);
63 return timezone_str;
64}
65
66int TimezoneOffset(void) {
67 const char *timezone_str;
68 int timezone_offset;
69 GetTimezoneInfo(timezone_str, timezone_offset);
70 return timezone_offset;
71}
const char * TimezoneString(void)
Definition timezone.cpp:59
int TimezoneOffset(void)
Definition timezone.cpp:66
void GetTimezoneInfo(const char *&timezone_str, int &timezone_offset)
Definition timezone.cpp:22