Celestia

Форк
0
/
tzutil.cpp 
68 строк · 1.6 Кб
1
// tzutil.cpp
2
//
3
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
4
//
5
// Miscellaneous useful functions.
6
//
7
// This program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public License
9
// as published by the Free Software Foundation; either version 2
10
// of the License, or (at your option) any later version.
11

12
#ifdef _WIN32
13
#include <windows.h>
14
#include "winutil.h"
15
#include "gettext.h"
16
#include "logger.h"
17

18
namespace util = celestia::util;
19

20
#else
21
// we need the C version of this header to get the POSIX function localtime_r
22
#include <time.h>
23
#endif
24

25
#include "tzutil.h"
26

27
bool GetTZInfo(std::string& tzName, int& dstBias)
28
{
29
#ifdef _WIN32
30
    using celestia::util::GetLogger;
31

32
    TIME_ZONE_INFORMATION tzi;
33
    DWORD dst = GetTimeZoneInformation(&tzi);
34
    if (dst == TIME_ZONE_ID_INVALID)
35
        return false;
36

37
    LONG bias = 0;
38
    WCHAR* name = nullptr;
39

40
    switch (dst)
41
    {
42
    case TIME_ZONE_ID_STANDARD:
43
        bias = tzi.StandardBias;
44
        name = tzi.StandardName;
45
        break;
46
    case TIME_ZONE_ID_DAYLIGHT:
47
        bias = tzi.DaylightBias;
48
        name = tzi.DaylightName;
49
        break;
50
    default:
51
        GetLogger()->warn(_("Unknown value returned by GetTimeZoneInformation()\n"));
52
        return false;
53
    }
54

55
    tzName = name == nullptr ? "   " : util::WideToUTF8(name);
56
    dstBias = (tzi.Bias + bias) * -60;
57
    return true;
58
#else
59
    tm result;
60
    time_t curtime = time(nullptr); // required only to get TZ info
61
    if (!localtime_r(&curtime, &result))
62
        return false;
63

64
    dstBias = result.tm_gmtoff;
65
    tzName = result.tm_zone;
66
    return true;
67
#endif
68
}
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.