Fixes in datetime
This commit is contained in:
parent
e2621bd4f8
commit
f74fd45234
1 changed files with 386 additions and 49 deletions
|
|
@ -2,18 +2,37 @@ import time
|
|||
from datetime import date, datetime, tzinfo
|
||||
import arrow
|
||||
# from babel.dates import format_date, format_datetime, format_time, get_timezone, UTC
|
||||
from settings import config
|
||||
from paramecio.citoplasma.sessions import get_session
|
||||
try:
|
||||
from settings import config
|
||||
except:
|
||||
config={}
|
||||
#from paramecio.citoplasma.sessions import get_session
|
||||
from os import environ
|
||||
|
||||
"""Simple hook for timedate functions from Arrow datetime module. Maybe in the future use native python datetime functions or other libraries. Is simply an abstraction for not depend of particular library.
|
||||
"""
|
||||
|
||||
sql_format_time='YYYYMMDDHHmmss'
|
||||
"""str: variable for define basic string for format dates
|
||||
|
||||
|
||||
By default, datetime module use YYYYMMDDHHmmss string for define dates and time. Tipically is used for sql operations in paramecio2 framework.
|
||||
"""
|
||||
|
||||
format_date_txt="YYYY/MM/DD"
|
||||
"""str: variable for define basic formatted date string
|
||||
"""
|
||||
|
||||
format_time_txt="HH:mm:ss"
|
||||
"""str: variable for define basic formatted time string
|
||||
"""
|
||||
|
||||
timezone='Europe/Madrid'
|
||||
"""str: basic timezone for dates, by default, Europe/Madrid
|
||||
"""
|
||||
|
||||
"""If default are changed in settings/config, change variables
|
||||
"""
|
||||
|
||||
if hasattr(config, 'format_date'):
|
||||
format_date_txt=config.format_date
|
||||
|
|
@ -25,6 +44,8 @@ if hasattr(config, 'timezone'):
|
|||
timezone=config.timezone
|
||||
|
||||
def set_timezone():
|
||||
"""Simple function for change the timezone in general environment of python
|
||||
"""
|
||||
|
||||
environ['TZ']=environ.get('TZ', timezone)
|
||||
|
||||
|
|
@ -32,6 +53,7 @@ def set_timezone():
|
|||
environ['TZ']=timezone
|
||||
time.tzset()
|
||||
|
||||
"""
|
||||
def set_timezone_session():
|
||||
|
||||
s=get_session()
|
||||
|
|
@ -50,8 +72,18 @@ def set_timezone_session():
|
|||
time.tzset()
|
||||
|
||||
#request.environ['TIMEZONE'] = request.environ['PATH_INFO'].rstrip('/')
|
||||
"""
|
||||
|
||||
def format_timedata(time):
|
||||
"""Function for get separated year, month, day, hour, minute and second from sql_format_time string
|
||||
|
||||
Args:
|
||||
time (str): A YYYYMMDDHHmmss string for get datetime components from there.
|
||||
|
||||
Returns:
|
||||
list: A dict with datetime components (year, month, day, hour, minute, second).
|
||||
|
||||
"""
|
||||
|
||||
year=0
|
||||
month=0
|
||||
|
|
@ -88,6 +120,20 @@ def format_timedata(time):
|
|||
return (year, month, day, hour, minute, second)
|
||||
|
||||
def checkdatetime(y, m, d, h, mi, s):
|
||||
"""Check if a series of datetime separated elements are correct, the datetime values are type int
|
||||
|
||||
Args:
|
||||
y (int): Year of datetime
|
||||
m (int): month
|
||||
d (int): day
|
||||
h (int): hour
|
||||
mi (int): minute
|
||||
s (int): seconds
|
||||
|
||||
Returns:
|
||||
bool: If values are correct, return True, otherwise return False
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
#test=datetime.strptime(str(y)+'-'+str(m)+'-'+str(d)+' '+str(h)+'-'+str(mi)+'-'+str(s), '%Y-%m-%d %H-%M-%S')
|
||||
|
|
@ -99,19 +145,16 @@ def checkdatetime(y, m, d, h, mi, s):
|
|||
# Get the localtime
|
||||
|
||||
def now(utc=False, tz=''):
|
||||
"""
|
||||
actual=datetime.today()
|
||||
|
||||
# Get localtime
|
||||
"""Returns the actual datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
final_date=actual.strftime(sql_format_time)
|
||||
#Go to gmt
|
||||
Args:
|
||||
utc (bool): If True, the datetime is returned in UTC timezone
|
||||
tz (str, optional): Timezone name, example: Europe/Madrid. If set the datetime is returned in the timezone selected
|
||||
|
||||
if utc:
|
||||
Returns:
|
||||
str: Return actual datetime
|
||||
|
||||
final_date=local_to_gmt(final_date)
|
||||
|
||||
return final_date
|
||||
"""
|
||||
|
||||
if not utc:
|
||||
|
|
@ -128,11 +171,35 @@ def now(utc=False, tz=''):
|
|||
|
||||
def today(utc=False,tz=''):
|
||||
|
||||
"""Returns the actual date in YYYYMMDDHHmmss format.
|
||||
|
||||
Is different from (now) function because return the date to 00:00:00 time
|
||||
|
||||
Args:
|
||||
utc (bool): If True, the date is returned in UTC timezone
|
||||
tz (str, optional): Timezone name, example: Europe/Madrid. If set the date is returned in the timezone selected
|
||||
|
||||
Returns:
|
||||
str: Return actual date with 00:00:00 how time
|
||||
|
||||
"""
|
||||
|
||||
return now(utc, tz)[:8]+'000000'
|
||||
|
||||
# Get actual timestamp
|
||||
|
||||
def obtain_timestamp(timeform, local=False, tz=''):
|
||||
def obtain_timestamp(timeform):
|
||||
|
||||
"""Get the timestamp from datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
Args:
|
||||
timeform (str): Datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
Returns:
|
||||
|
||||
int: datetime in timestamp format
|
||||
|
||||
"""
|
||||
|
||||
y, m, d, h, mi, s=format_timedata(timeform)
|
||||
|
||||
|
|
@ -140,20 +207,6 @@ def obtain_timestamp(timeform, local=False, tz=''):
|
|||
|
||||
#timestamp=int(time.mktime((y, m, d, h, mi, s, 0, 0, -1)))
|
||||
|
||||
if local:
|
||||
|
||||
#offset=time.altzone
|
||||
|
||||
#return timestamp-offset
|
||||
|
||||
if tz=='':
|
||||
tz=environ.get('TZ', 'utc')
|
||||
|
||||
t=arrow.arrow.Arrow(y, m, d, h, mi, s).to(tz)
|
||||
|
||||
timestamp=t.timestamp()
|
||||
|
||||
else:
|
||||
timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp()
|
||||
|
||||
return timestamp
|
||||
|
|
@ -164,21 +217,34 @@ def obtain_timestamp(timeform, local=False, tz=''):
|
|||
|
||||
# timestamp is gmt time, convert in normal time
|
||||
|
||||
def timestamp_to_datetime(timestamp):
|
||||
def timestamp_to_datetime(timestamp, sql_format_time=sql_format_time):
|
||||
|
||||
#time_set=substract_utc(timestamp)
|
||||
"""Turn datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
#return time.strftime(sql_format_time, time_set)
|
||||
Args:
|
||||
timestamp (int): The timestamp for convert
|
||||
|
||||
Returns:
|
||||
str: Datetime in YYYYMMDDHHmmss format
|
||||
|
||||
"""
|
||||
|
||||
return arrow.get(timestamp).format(sql_format_time)
|
||||
|
||||
# Get a utc timestamp and convert to local
|
||||
|
||||
def timestamp_to_datetime_local(timestamp, tz=''):
|
||||
def timestamp_to_datetime_local(timestamp, tz='', sql_format_time=sql_format_time):
|
||||
"""Get a utc timestamp and convert to timezone datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
#time_set=time.localtime(timestamp)
|
||||
Args:
|
||||
timestamp (int): The timestamp for convert in datetime
|
||||
tz (str, optional): If you want convert to other timezone, set it.
|
||||
|
||||
#return time.strftime(sql_format_time, time_set)
|
||||
Returns:
|
||||
|
||||
str: Datetime in YYYYMMDDHHmmss format in selected timezone datetime
|
||||
|
||||
"""
|
||||
|
||||
t=arrow.get(timestamp)
|
||||
|
||||
|
|
@ -190,6 +256,18 @@ def timestamp_to_datetime_local(timestamp, tz=''):
|
|||
|
||||
def format_datetime(format_time, timeform, func_utc_return):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in other str datetime (normally, same YYYYMMDDHHmmss format). Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
format_time (str): The strtime string used for format the datetime
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
func_utc_return (function): A function used for get the datetime.
|
||||
|
||||
Returns:
|
||||
If timestamp is False, return False, if timestamp is valid, return the datetime formatted
|
||||
|
||||
"""
|
||||
|
||||
timestamp=obtain_timestamp(timeform)
|
||||
|
||||
if timestamp:
|
||||
|
|
@ -206,50 +284,159 @@ def format_datetime(format_time, timeform, func_utc_return):
|
|||
|
||||
def local_to_gmt(timeform, sql_format_time=sql_format_time):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in other str datetime. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Expects that timeform was in time not gmt and convert to gmt
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
sql_format_time (str, optional): by default, the format is YYYYMMDDHHmmss, you can put other formatted str formats for date, here.
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
|
||||
"""
|
||||
|
||||
return format_datetime(sql_format_time, timeform, substract_utc)
|
||||
|
||||
# time.localtime is useless, you need sum the time offset to the date
|
||||
|
||||
def gmt_to_local(timeform, sql_format_time=sql_format_time):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format in UTC and convert in other str datetime. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Expects that timeform was in time gmt and convert to localtime
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
sql_format_time (str, optional): by default, the format is YYYYMMDDHHmmss, you can put other formatted str formats for date, here.
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
|
||||
"""
|
||||
|
||||
return format_datetime(sql_format_time, timeform, sum_utc)
|
||||
|
||||
def format_time(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in HH:mm:ss UTC format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted in UTC
|
||||
|
||||
"""
|
||||
|
||||
return format_datetime(format_time_txt, timeform, sum_utc)
|
||||
|
||||
def format_date(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in YYYY/MM/DD UTC format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted in UTC
|
||||
"""
|
||||
|
||||
return format_datetime(format_date_txt, timeform, sum_utc)
|
||||
|
||||
def format_fulldate(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in YYYY/MM/DD HH:mm:ss UTC format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted in UTC
|
||||
"""
|
||||
|
||||
return format_datetime(format_date_txt+' '+format_time_txt, timeform, sum_utc)
|
||||
|
||||
def format_local_time(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in HH:mm:ss format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
"""
|
||||
|
||||
return format_datetime(format_time_txt, timeform, no_utc)
|
||||
|
||||
def format_local_date(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in YYYY/MM/DD format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
"""
|
||||
|
||||
return format_datetime(format_date_txt, timeform, no_utc)
|
||||
|
||||
def format_local_fulldate(timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in YYYY/MM/DD HH:mm:ss format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
"""
|
||||
|
||||
return format_datetime(format_date_txt+' '+format_time_txt, timeform, no_utc)
|
||||
|
||||
def format_strtime(strtime, timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in strtime string UTC format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted in UTC
|
||||
"""
|
||||
|
||||
return format_datetime(strtime, timeform, sum_utc)
|
||||
|
||||
def format_local_strtime(strtime, timeform):
|
||||
|
||||
"""Get a datetime in YYYYMMDDHHmmss format and convert in strtime string format. Is a primitive function for other high level datetime functions.
|
||||
|
||||
Args:
|
||||
timeform (str): datetime in YYYYMMDDHHmmss format to convert to new format
|
||||
|
||||
Returns:
|
||||
If timeform is False, return False, if timeform is valid, return the datetime formatted
|
||||
"""
|
||||
|
||||
return format_datetime(strtime, timeform, no_utc)
|
||||
|
||||
#Input is utc timestamp, return local arrow object
|
||||
|
||||
def sum_utc(timestamp, tz=''):
|
||||
|
||||
"""Get timestamp in UTC and convert in arrow date object with timezone datetime
|
||||
|
||||
Args:
|
||||
timestamp (int): The timestamp for convert in other timezone
|
||||
tz (str): Timezone of timestamp
|
||||
|
||||
Returns:
|
||||
Return arrow object with new timezone selected
|
||||
"""
|
||||
|
||||
#offset=time.altzone
|
||||
|
||||
#return time.localtime(timestamp-offset)
|
||||
|
|
@ -265,6 +452,16 @@ def sum_utc(timestamp, tz=''):
|
|||
|
||||
def substract_utc(timestamp, tz=''):
|
||||
|
||||
"""Get local timestamp and convert in arrow date object with UTC datetime
|
||||
|
||||
Args:
|
||||
timestamp (int): The timestamp for convert in UTC timezone
|
||||
tz (str): Timezone of timestamp
|
||||
|
||||
Returns:
|
||||
Return arrow object with UTC timezone selected
|
||||
"""
|
||||
|
||||
#offset=time.altzone
|
||||
|
||||
#return time.localtime(timestamp+offset)
|
||||
|
|
@ -284,13 +481,34 @@ def substract_utc(timestamp, tz=''):
|
|||
|
||||
def no_utc(timestamp):
|
||||
|
||||
"""Return an arrow object based in timestamp value
|
||||
|
||||
Args:
|
||||
timestamp (int): The timestamp for convert in UTC timezone
|
||||
|
||||
Returns:
|
||||
Return arrow object based in timestamp value
|
||||
|
||||
"""
|
||||
|
||||
return arrow.get(timestamp)
|
||||
|
||||
# def date_to_sql(date_sql):
|
||||
|
||||
|
||||
|
||||
class TimeClass:
|
||||
"""Simple abstraction of arrow class, in future i can change arrow class by others
|
||||
|
||||
Args:
|
||||
timestamp (int, str, optional): You can set the initial arrow object with timestamp date or YYYYMMDDHHmmss date format
|
||||
tz (str): Timezone
|
||||
|
||||
Attributes:
|
||||
utc (bool): If True, the default timezone is UTC, if False, timezone is system default
|
||||
format_time (str): The default datetime format, YYYYMMDDHHmmss
|
||||
format_time_txt (str): Time text format, usually HH:mm:ss
|
||||
format_date_txt (str): Date text format, usually YYYY/MM/DD
|
||||
format_date_full (str): Full DateTime text format, usually YYYY/MM/DD HH:mm:ss
|
||||
tz (str): Default timezone for arrow object
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, timestamp=None, tz=''):
|
||||
|
||||
|
|
@ -309,13 +527,7 @@ class TimeClass:
|
|||
self.tz=tz
|
||||
|
||||
if type(timestamp).__name__=='int':
|
||||
"""
|
||||
if self.utc:
|
||||
|
||||
self.datetime=utcnow()
|
||||
|
||||
else:
|
||||
"""
|
||||
self.datetime=timestamp_to_datetime(timestamp)
|
||||
|
||||
else:
|
||||
|
|
@ -332,72 +544,154 @@ class TimeClass:
|
|||
self.t=arrow.get(datetime(y, m, d, h, mi, s), self.tz)
|
||||
|
||||
def add_month(self, num_months):
|
||||
"""Method for add months to datetime
|
||||
|
||||
Args:
|
||||
num_months (int): Number of months to add
|
||||
|
||||
Returns:
|
||||
New added datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(months=+num_months)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def substract_month(self, num_months):
|
||||
"""Method for substract months to datetime
|
||||
|
||||
Args:
|
||||
num_months (int): Number of months to substract
|
||||
|
||||
Returns:
|
||||
New substracted datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(months=-num_months)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def add_day(self, num_days):
|
||||
"""Method for add days to datetime
|
||||
|
||||
Args:
|
||||
num_days (int): Number of days to add
|
||||
|
||||
Returns:
|
||||
New added datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(days=+num_days)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def substract_day(self, num_days):
|
||||
"""Method for substract days to datetime
|
||||
|
||||
Args:
|
||||
num_days (int): Number of days to substract
|
||||
|
||||
Returns:
|
||||
New substracted datetime
|
||||
|
||||
"""
|
||||
|
||||
m=self.t.shift(days=-num_days)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def add_year(self, num_years):
|
||||
"""Method for add years to datetime
|
||||
|
||||
Args:
|
||||
num_years (int): Number of years to add
|
||||
|
||||
Returns:
|
||||
New added datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(years=+num_years)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def substract_year(self, num_years):
|
||||
"""Method for substract years to datetime
|
||||
|
||||
Args:
|
||||
num_years (int): Number of years to substract
|
||||
|
||||
Returns:
|
||||
New substracted datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(years=-num_years)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def add_hour(self, num_hours):
|
||||
"""Method for add hours to datetime
|
||||
|
||||
Args:
|
||||
num_hours (int): Number of hours to add
|
||||
|
||||
Returns:
|
||||
New added datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(hours=+num_hours)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def substract_hour(self, num_hours):
|
||||
"""Method for substract hours to datetime
|
||||
|
||||
Args:
|
||||
num_hours (int): Number of hours to substract
|
||||
|
||||
Returns:
|
||||
New substracted datetime
|
||||
"""
|
||||
|
||||
m=self.t.shift(hours=-num_hours)
|
||||
|
||||
return m.format(self.format_time)
|
||||
|
||||
def format(self):
|
||||
"""Method for get datetime formatted using format_date_full attribute
|
||||
|
||||
Returns:
|
||||
Datetime formatted with format_date_full attribute
|
||||
"""
|
||||
|
||||
return self.t.format(self.format_date_full)
|
||||
|
||||
def local_to_utc(self):
|
||||
"""Method for convert datetime from actual timezone to UTC"""
|
||||
|
||||
self.t=self.t.to('utc')
|
||||
|
||||
# Only use
|
||||
|
||||
def utc_to_local(self):
|
||||
"""Method for convert datetime from actual timezone from UTC to actual timezone"""
|
||||
|
||||
self.t=self.t.to(self.tz)
|
||||
|
||||
def local_to_tz(self, tz):
|
||||
"""Method for convert actual timezone to other timezone"""
|
||||
|
||||
self.t=self.t.to(tz)
|
||||
|
||||
def now(self, utc=False):
|
||||
"""Method for get actual datetime.
|
||||
|
||||
Args:
|
||||
utc (bool): If True, then get actual datetime in UTC datetime, if False, get actual datetime in selected timezone in tz attribute
|
||||
|
||||
Returns:
|
||||
|
||||
Actual datetime formatted in YYYYMMDDHHmmss format.
|
||||
"""
|
||||
|
||||
if not utc:
|
||||
|
||||
|
|
@ -409,6 +703,16 @@ class TimeClass:
|
|||
|
||||
def today(self, utc=False):
|
||||
|
||||
"""Method for get today datetime. Get now datetime with 00:00:00 time.
|
||||
|
||||
Args:
|
||||
utc (bool): If True, then get actual datetime in UTC datetime, if False, get actual datetime in selected timezone in tz attribute
|
||||
|
||||
Returns:
|
||||
|
||||
Actual datetime formatted in YYYYMMDD000000 format.
|
||||
"""
|
||||
|
||||
if utc:
|
||||
|
||||
return arrow.utcnow()[:8]+'000000'
|
||||
|
|
@ -417,15 +721,36 @@ class TimeClass:
|
|||
|
||||
def timestamp_to_datetime(self, timestamp):
|
||||
|
||||
"""Method for convert a timestamp in YYYYMMDDHHmmss format.
|
||||
|
||||
Args:
|
||||
|
||||
timestamp (int): datetime in timestamp format.
|
||||
|
||||
Returns:
|
||||
|
||||
Datetime in YYYYMMDDHHmmss format.
|
||||
"""
|
||||
|
||||
return arrow.get(timestamp).format(sql_format_time)
|
||||
|
||||
def obtain_timestamp(self, timeform):
|
||||
|
||||
"""Method for get timestamp from a datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
Args:
|
||||
timeform (str): Datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
Returns:
|
||||
|
||||
Datetime in YYYYMMDDHHmmss format.If timeform is incorrect, return False
|
||||
"""
|
||||
|
||||
y, m, d, h, mi, s=format_timedata(timeform)
|
||||
|
||||
if checkdatetime(y, m, d, h, mi, s):
|
||||
|
||||
timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp()
|
||||
timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp
|
||||
|
||||
return timestamp
|
||||
|
||||
|
|
@ -434,7 +759,19 @@ class TimeClass:
|
|||
|
||||
def format_strtime(self, strtime, timeform):
|
||||
|
||||
#timestamp=self.obtain_timestamp(timeform)
|
||||
"""Method for get datetime formatted in strtime format
|
||||
|
||||
Args:
|
||||
strtime (str): The string used for format the datetime
|
||||
timeform (str): Datetime in YYYYMMDDHHmmss format.
|
||||
|
||||
Returns:
|
||||
|
||||
Datetime in strtime format.If timeform is incorrect, return False
|
||||
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
y, m, d, h, mi, s=format_timedata(timeform)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue