Fixes in datetime

This commit is contained in:
Antonio de la Rosa 2017-11-21 04:57:56 +01:00
parent ae15a6e358
commit e6864bf230
2 changed files with 14 additions and 31 deletions

View file

@ -389,52 +389,33 @@ class TimeClass:
def today(self, utc=False): def today(self, utc=False):
return now(utc, self.tz)[:8]+'000000' return self.now(utc)[:8]+'000000'
def timestamp_to_datetime(self, timestamp, utc=False): def timestamp_to_datetime(self, timestamp):
if utc: return arrow.get(timestamp).format(sql_format_time)
return self.t.get(timestamp).to('UTC').format(sql_format_time) def obtain_timestamp(self, timeform):
else:
return self.t.get(timestamp).format(sql_format_time)
def obtain_timestamp(self, timeform, utc=False):
y, m, d, h, mi, s=format_timedata(timeform) y, m, d, h, mi, s=format_timedata(timeform)
if checkdatetime(y, m, d, h, mi, s): if checkdatetime(y, m, d, h, mi, s):
#timestamp=int(time.mktime((y, m, d, h, mi, s, 0, 0, -1)))
if local:
#offset=time.altzone
#return timestamp-offset
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 timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp
return timestamp return timestamp
#return mktime($h, $mi, $s, $m, $d, $y);
else: else:
return False return False
def format_strtime(self, strtime, timeform): def format_strtime(self, strtime, timeform):
timestamp=obtain_timestamp(timeform) #timestamp=self.obtain_timestamp(timeform)
try:
y, m, d, h, mi, s=format_timedata(timeform)
if timestamp: return arrow.get(datetime(y, m, d, h, mi, s), self.tz).format(strtime)
return self.t.get(timestamp).format(strtime) except:
else:
return False return False

View file

@ -100,7 +100,9 @@ class TestClassMethods(unittest.TestCase):
self.assertEqual('20121203231248', d.add_day(7)) self.assertEqual('20121203231248', d.add_day(7))
self.assertEqual('20121119231248', d.substract_day(7)) self.assertEqual('20121119231248', d.substract_day(7))
#self.assertEqual('20121203231248', d.substract_day(7))
#timestamp=d.obtain_timestamp('20121126231248')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()