forked from CelestiaProject/Celestia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
61 lines (54 loc) · 1.47 KB
/
util.cpp
File metadata and controls
61 lines (54 loc) · 1.47 KB
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
// util.cpp
//
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
//
// Miscellaneous useful functions.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#ifdef _WIN32
#include <windows.h>
#include <celutil/winutil.h>
#endif
#include <iostream>
#include "util.h"
#include "gettext.h"
using namespace std;
bool GetTZInfo(std::string_view tzName, int &dstBias)
{
#ifdef _WIN32
TIME_ZONE_INFORMATION tzi;
DWORD dst = GetTimeZoneInformation(&tzi);
if (dst == TIME_ZONE_ID_INVALID)
return false;
LONG bias = 0;
WCHAR* name = nullptr;
switch (dst)
{
case TIME_ZONE_ID_STANDARD:
bias = tzi.StandardBias;
name = tzi.StandardName;
break;
case TIME_ZONE_ID_DAYLIGHT:
bias = tzi.DaylightBias;
name = tzi.DaylightName;
break;
default:
cerr << _("Unknown value returned by GetTimeZoneInformation()\n");
return false;
}
tzName = name == nullptr ? " " : WideToUTF8(name);
dstBias = (tzi.Bias + bias) * -60;
return true;
#else
struct tm result;
time_t curtime = time(nullptr); // required only to get TZ info
if (!localtime_r(&curtime, &result))
return false;
dstBias = result.tm_gmtoff;
tzName = result.tm_zone;
return true;
#endif
}