from jinja2 import Markup
from datetime import datetime, timedelta
from models import Event

class momentjs(object):
    def __init__(self, timestamp):
        self.timestamp = timestamp

    def render(self, format):
        return Markup("<script>\ndocument.write(moment(\"%s\").%s);\n</script>" % (self.timestamp.strftime("%Y-%m-%dT%H:%M:%S Z"), format))

    def format(self, fmt):
        return self.render("format(\"%s\")" % fmt)

    def calendar(self):
        return self.render("calendar()")

    def fromNow(self):
        return self.render("fromNow()")
    
    def DaysUntil(self):
        delta=self.timestamp-datetime.today()
        return max(delta.days,0)

    @staticmethod
    def NextBeginPotentialDate():
        return Event.getNextDate().strftime("%d/%m/%Y 20:00")

    @staticmethod
    def NextEndPotentialDate():
        return (Event.getNextDate()+timedelta(1)).strftime("%d/%m/%Y 00:00")


