from django.contrib.auth.models import User
import django.db
from django.db import models
from django.utils.timezone import localtime
import datetime


class OfficeHours(models.Model):
    begins_at = models.DateTimeField()
    ends_at = models.DateTimeField()
    user = models.ForeignKey(User, on_delete=django.db.models.deletion.CASCADE)

    @classmethod
    def parse_time_str(cls, time_srt):
        return datetime.datetime.strptime(time_srt, '%Y-%m-%d %H:%M')

    @classmethod
    def get_ends_at(cls, begins_at):
        return begins_at + datetime.timedelta(hours=9.5)

    @property
    def get_begins_at_str(self):
        return localtime(self.begins_at).strftime('%Y-%m-%d %H:%M')

    @property
    def get_ends_at_str(self):
        return localtime(self.ends_at).strftime('%H:%M')
