Package backend :: Package common :: Module timezone_utils
[hide private]
[frames] | no frames]

Source Code for Module backend.common.timezone_utils

 1  """ 
 2  Copyright (C) 2017 Oracle and/or its affiliates. All rights reserved. 
 3   
 4  This program is free software; you can redistribute it and/or 
 5  modify it under the terms of the GNU General Public License 
 6  as published by the Free Software Foundation, version 2 
 7   
 8   
 9  This program is distributed in the hope that it will be useful, 
10  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  GNU General Public License for more details. 
13   
14  You should have received a copy of the GNU General Public License 
15  along with this program; if not, write to the Free Software 
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
17  02110-1301, USA. 
18   
19  Utility to get system UTC offset and format as needed by DBs. 
20  """ 
21  import time 
22   
23   
24 -def get_utc_offset():
25 """Return the UTC offset, allowing for DST.""" 26 is_dst = time.daylight and time.localtime().tm_isdst > 0 27 utc_offset = - time.timezone 28 if is_dst: 29 utc_offset = - time.altzone 30 mins = divmod(utc_offset, 60)[0] 31 hours, mins = divmod(mins, 60) 32 return '{0:+03d}:{1:02d}'.format(hours, mins)
33 34 35 if __name__ == "__main__": 36 print "UTC offset (allowing for DST if in effect): %s" % get_utc_offset() 37