# Path: fbone/appointment/forms.py
# class MakeAppointmentForm(Form):
#     next = HiddenField()
# 
#     name = TextField(u'Name',
#                      [Required(),
#                       Length(USERNAME_LEN_MIN, USERNAME_LEN_MAX)])
#     time_range = TimeRangeSliderField(u'Time Range')
#     start_time = HiddenField(u'start_time')
#     end_time = HiddenField(u'end_time')
#     email = EmailField(u'Email',
#                        [Email(),
#                         Length(EMAIL_LEN_MIN, EMAIL_LEN_MAX)])
#     date = DateField(u'Date',
#                      [Required()],
#                      default=datetime.date.today())
#     timezone = SelectOptgroupField(u'Timezone',
#                                    [Required(),
#                                     Length(TIMEZONE_LEN_MIN,
#                                            TIMEZONE_LEN_MAX)],
#                                    choices=TIMEZONES)
#     message = TextAreaField(u'Message',
#                             [Required(),
#                              Length(MESSAGE_LEN_MIN, MESSAGE_LEN_MAX)],
#                             description={'placeholder': MESSAGE_PLACEHOLDER})
#     submit = SubmitField('OK')
# 
# Path: fbone/appointment/models.py
# class Appointment(db.Model):
# 
#     __tablename__ = 'appointments'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(USERNAME_LEN_MAX), nullable=False)
#     email = db.Column(db.String(EMAIL_LEN_MAX), nullable=False)
#     start_time = db.Column(db.Integer, nullable=False)
#     end_time = db.Column(db.Integer, nullable=False)
#     timezone = db.Column(db.String(TIMEZONE_LEN_MAX), nullable=False)
#     message = db.Column(db.String(MESSAGE_LEN_MAX), nullable=False)


from datetime import datetime, date
from flask import (Blueprint, render_template, request, abort, flash, url_for,
                   redirect, session, current_app, jsonify)
from flask.ext.mail import Message
from sqlalchemy.sql import select, and_, or_
from ..extensions import db, mail
from .forms import MakeAppointmentForm
from .models import Appointment
import smtplib

    date_obj: a datetime.date object
    minutes: an integer in [0, 1400]
    timezone: an float in [-12, 12]

    return: seconds from epcoh time.
    """
    epoch_date = date(1970, 1, 1)
    seconds = (date_obj - epoch_date).total_seconds()
    seconds += minutes * 60
    seconds -= timezone * 3600

    return int(seconds)


def get_local_minutes(seconds, date_obj, timezone):
    init_seconds = get_utc_seconds(date_obj, 0, timezone)
    delta_seconds = seconds - init_seconds
    if delta_seconds < 0:
        delta_seconds = 0
    elif delta_seconds > 86400:
        delta_seconds = 86400

    return delta_seconds / 60


def appointment_ok(appointment):
    if appointment.start_time >= appointment.end_time:
        return False, "Start time %s and end time %s is illegal." % \
            (appointment.start_time, appointment.end_time)

# Path: fbone/appointment/forms.py
# class MakeAppointmentForm(Form):
#     next = HiddenField()
# 
#     name = TextField(u'Name',
#                      [Required(),
#                       Length(USERNAME_LEN_MIN, USERNAME_LEN_MAX)])
#     time_range = TimeRangeSliderField(u'Time Range')
#     start_time = HiddenField(u'start_time')
#     end_time = HiddenField(u'end_time')
#     email = EmailField(u'Email',
#                        [Email(),
#                         Length(EMAIL_LEN_MIN, EMAIL_LEN_MAX)])
#     date = DateField(u'Date',
#                      [Required()],
#                      default=datetime.date.today())
#     timezone = SelectOptgroupField(u'Timezone',
#                                    [Required(),
#                                     Length(TIMEZONE_LEN_MIN,
#                                            TIMEZONE_LEN_MAX)],
#                                    choices=TIMEZONES)
#     message = TextAreaField(u'Message',
#                             [Required(),
#                              Length(MESSAGE_LEN_MIN, MESSAGE_LEN_MAX)],
#                             description={'placeholder': MESSAGE_PLACEHOLDER})
#     submit = SubmitField('OK')
# 
# Path: fbone/appointment/models.py
# class Appointment(db.Model):
# 
#     __tablename__ = 'appointments'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(USERNAME_LEN_MAX), nullable=False)
#     email = db.Column(db.String(EMAIL_LEN_MAX), nullable=False)
#     start_time = db.Column(db.Integer, nullable=False)
#     end_time = db.Column(db.Integer, nullable=False)
#     timezone = db.Column(db.String(TIMEZONE_LEN_MAX), nullable=False)
#     message = db.Column(db.String(MESSAGE_LEN_MAX), nullable=False)


# Path: fbone/appointment/views.py
from datetime import datetime, date
from flask import (Blueprint, render_template, request, abort, flash, url_for,
                   redirect, session, current_app, jsonify)
from flask.ext.mail import Message
from sqlalchemy.sql import select, and_, or_
from ..extensions import db, mail
from .forms import MakeAppointmentForm
from .models import Appointment
import smtplib


    date_obj: a datetime.date object
    minutes: an integer in [0, 1400]
    timezone: an float in [-12, 12]

    return: seconds from epcoh time.
    """
    epoch_date = date(1970, 1, 1)
    seconds = (date_obj - epoch_date).total_seconds()
    seconds += minutes * 60
    seconds -= timezone * 3600

    return int(seconds)


def get_local_minutes(seconds, date_obj, timezone):
    init_seconds = get_utc_seconds(date_obj, 0, timezone)
    delta_seconds = seconds - init_seconds
    if delta_seconds < 0:
        delta_seconds = 0
    elif delta_seconds > 86400:
        delta_seconds = 86400

    return delta_seconds / 60


def appointment_ok(appointment):
    if appointment.start_time >= appointment.end_time:
        return False, "Start time %s and end time %s is illegal." % \
            (appointment.start_time, appointment.end_time)

    start = Appointment.query.filter(Appointment.start_time <