aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/Timezone_VX.cpp
blob: 79a8a78066147a7ee9d3b0b75ad57b363fa0235d (plain) (blame)
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
// 
// Timezone_VXX.cpp 
// 
// Library: Foundation 
// Package: DateTime 
// Module:  Timezone 
// 
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH. 
// and Contributors. 
// 
// SPDX-License-Identifier:	BSL-1.0 
// 
 
 
#include "Poco/Timezone.h" 
#include "Poco/Exception.h" 
#include "Poco/Environment.h" 
#include <ctime> 
 
 
namespace Poco { 
 
 
int Timezone::utcOffset() 
{ 
	std::time_t now = std::time(NULL); 
	struct std::tm t; 
	gmtime_r(&now, &t); 
	std::time_t utc = std::mktime(&t); 
	return now - utc; 
} 
 
	 
int Timezone::dst() 
{ 
	std::time_t now = std::time(NULL); 
	struct std::tm t; 
	if (localtime_r(&now, &t) != OK) 
		throw Poco::SystemException("cannot get local time DST offset"); 
	return t.tm_isdst == 1 ? 3600 : 0; 
} 
 
 
bool Timezone::isDst(const Timestamp& timestamp) 
{ 
	std::time_t time = timestamp.epochTime(); 
	struct std::tm* tms = std::localtime(&time); 
	if (!tms) throw Poco::SystemException("cannot get local time DST flag"); 
	return tms->tm_isdst > 0; 
} 
 
	 
std::string Timezone::name() 
{ 
	// format of TIMEZONE environment variable: 
	// name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end 
	std::string tz = Environment::get("TIMEZONE", "UTC"); 
	std::string::size_type pos = tz.find(':'); 
	if (pos != std::string::npos) 
		return tz.substr(0, pos); 
	else 
		return tz; 
} 
 
	 
std::string Timezone::standardName() 
{ 
	return name(); 
} 
 
	 
std::string Timezone::dstName() 
{ 
	return name(); 
} 
 
 
} // namespace Poco