Tornado datetime
Question: How would I create a datetime stamp from a clients offset? I have been messing
around with this all day. The idea is to have a user login and based upon
their timezone to create the cookie to expire after so long.

    
    
    #!/usr/bin/env python
    
    import tornado.auth
    import tornado.database
    import tornado.httpserver
    import tornado.ioloop
    import tornado.options
    import tornado.web
    import tornado.escape
    import hashlib
    import unicodedata
    import markdown
    import os.path
    import re
    import urllib
    import sys
    import time
    import json
    import MySQLdb
    import Cookie
    from tornado.options import define, options
    import datetime
    from nptime import nptime
    
    define("port", default=8001, help="Server port", type=int)
    class Application(tornado.web.Application):
        def __init__(self):
            handlers = [
                (r"/", MainHandler),
                (r"/test", Test),
            ]
            tornado.web.Application.__init__(self, handlers)
    
            self.db = tornado.database.Connection(
                host=options.mysql_host, database=options.mysql_database,
                user=options.mysql_user, password=options.mysql_password)
    
    class BaseHandler(tornado.web.RequestHandler):
        @property
        def db(self):
            return self.application.db
    
    class MainHandler(BaseHandler):
        def get(self):
            self.set_header("Content-Type", "text/html")
            self.write()
            self.finish()
    
    class Test(BaseHandler):
        def post(self):
            tmz = self.get_argument('tmz', '')
            cur = datetime.datetime.utcnow().strftime('%A, %B %d, %Y %I:%M:%S %p 'tmz, gmtime())
            self.set_header("Content-Type", "text/html")
            self.write(cur)
            self.finish()
    
    def main():
        tornado.options.parse_command_line()
        http_server = tornado.httpserver.HTTPServer(Application())
        http_server.listen(options.port)
        tornado.ioloop.IOLoop.instance().start()
    
    
    if __name__ == "__main__":
        main()
    

Where tmz would be the timezone sent example -0400 or +0500


Answer: You could have a hidden datetime input pass the client's current time,
including timezone, into the login form:

    
    
    <input type="hidden" name="current_datetime" />
    

That input's value can be populated with javascript.

Then, in your post function, you can add hours or days to the value that
current_datetime passes in.

