Source code for glideinwms.lib.timeConversion
# SPDX-FileCopyrightText: 2009 Fermi Research Alliance, LLC
# SPDX-License-Identifier: Apache-2.0
#
# Project:
# glideinWMS
#
# File Version:
#
# Description:
# This module implements time2string functions
#
# Author:
# Igor Sfiligoi (Mar 15th 2007)
#
import calendar
import time
[docs]
def getSeconds(now=None):
if now is None:
now = time.time()
return "%li" % int(now)
[docs]
def getHuman(now=None):
if now is None:
now = time.time()
return time.strftime("%c", time.localtime(now))
[docs]
def getISO8601_UTC(now=None):
if now is None:
now = time.time()
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(now))
[docs]
def getISO8601_Local(now=None):
if now is None:
now = time.time()
tzval = getTZval(now)
return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(now)) + (
"%+03i:%02i" % ((-tzval // 3600), (-tzval % 3600 // 60))
)
[docs]
def getRFC2822_UTC(now=None):
if now is None:
now = time.time()
return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(now))
[docs]
def getRFC2822_Local(now=None):
if now is None:
now = time.time()
tzval = getTZval(now)
return time.strftime("%a, %d %b %Y %H:%M:%S ", time.localtime(now)) + (
"%+03i%02i" % ((-tzval // 3600), (-tzval % 3600 // 60))
)
#########################
# Internal
#########################
# time.daylight tells only if the computer support daylight saving time,
# tm_isdst must be checked to see if it is in effect at time t
# Some corner cases (changes in standard) are still uncovered, see https://bugs.python.org/issue1647654
# See also https://bugs.python.org/issue7229 for an improved explanation of the Python manual wording
[docs]
def getTZval(t):
if time.localtime(t).tm_isdst and time.daylight:
return time.altzone
else:
return time.timezone