<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
import datetime
from frappe.model.document import Document


class AppointmentBookingSettings(Document):
    min_date = '01/01/1970 '
    format_string = "%d/%m/%Y %H:%M:%S"

    def validate(self):
        self.validate_availability_of_slots()

    def validate_availability_of_slots(self):
        for record in self.availability_of_slots:
            from_time = datetime.datetime.strptime(
                self.min_date+record.from_time, self.format_string)
            to_time = datetime.datetime.strptime(
                self.min_date+record.to_time, self.format_string)
            timedelta = to_time-from_time
            self.from_time_is_later_than_to_time(from_time, to_time)
            self.duration_is_divisible(from_time, to_time)

    def from_time_is_later_than_to_time(self, from_time, to_time):
        if from_time > to_time:
            err_msg = 'From Time cannot be later than To Time for '+record.day_of_week
            frappe.throw(_(err_msg))

    def duration_is_divisible(self, from_time, to_time):
        timedelta = to_time - from_time
        if timedelta.total_seconds() % (self.appointment_duration * 60):
            frappe.throw(
                _('The difference between from time and To Time must be a multiple of Appointment'))<commit_msg>Apply suggestions from code review<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
import datetime
from frappe.model.document import Document


class AppointmentBookingSettings(Document):
    min_date = '01/01/1970 '
    format_string = "%d/%m/%Y %H:%M:%S"

    def validate(self):
        self.validate_availability_of_slots()

    def validate_availability_of_slots(self):
        for record in self.availability_of_slots:
            from_time = datetime.datetime.strptime(
                self.min_date+record.from_time, self.format_string)
            to_time = datetime.datetime.strptime(
                self.min_date+record.to_time, self.format_string)
            timedelta = to_time-from_time
            self.validate_from_and_to_time(from_time, to_time)
            self.duration_is_divisible(from_time, to_time)

    def validate_from_and_to_time(self, from_time, to_time):
        if from_time > to_time:
            err_msg = _(''<b>From Time</b> cannot be later than <b>To Time</b> for {0}'').format(record.day_of_week)
            frappe.throw(_(err_msg))

    def duration_is_divisible(self, from_time, to_time):
        timedelta = to_time - from_time
        if timedelta.total_seconds() % (self.appointment_duration * 60):
            frappe.throw(
                _('The difference between from time and To Time must be a multiple of Appointment'))
{'fraction_non_alphanumeric': 0.0873248615184099, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 3.060846560846561, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2896223', 'n_tokens_mistral': 978, 'n_tokens_neox': 935, 'n_words': 221}