In a web application I m writing for an existing database I need to calculate the difference between now and a timestamp stored in the database (in a text field, it s stupid, I know). Here s my sqlalchemy Ban
class and the relevant method.
class Ban(base):
__tablename__= bans
id= Column( banID , Integer, primary_key=True)
unban_timestamp= Column( UNBAN , Text)
banned_steamid= Column( ID , Text, ForeignKey( rp_users.steamid ))
banned_name= Column( NAME , Text)
banner_steamid= Column( BANNER_STEAMID , Text, ForeignKey( rp_users.steamid ))
banner_name= Column( BANNER , Text)
reason= Column( REASON , Text)
def unbanned_in(self, mode):
if self.unban_timestamp == 0 :
return Never
else:
now= datetime.datetime.utcnow()
time= datetime.datetime.fromtimestamp(int(self.unban_timestamp))
if now > time:
return Expired
else:
remaining= time - now
if mode== readable :
return remaining
elif mode== int :
return str(remaining.seconds).zfill(10)
我既需要愤怒,又需要粗略的描述,因为我将在一张html桌上提出这种说法,而 j印需要一种简单的方式加以分类。 I m面临的问题是,愤怒和扼杀不一样,正如你在这里看到的那样:
如果任何人能够感觉到产出为何如此rew升,那将受到赞赏! 如果掌握了你回答我问题所需要的更多信息,我很乐意补充。
edit
www.un.org/Depts/DGACM/index_french.htm 如果我通过我的职能来管理,这是我获得的结果。
>>> ban = session.query(db.Ban).filter_by(id=3783).one()
>>> print ban.unbanned_in( int ), ban.unbanned_in( readable )
0000049044 2 days, 13:37:24.179045