from . import Konvalidator, KonversionError, ValidationError
import datetime

class IsFuture(Konvalidator):
	''' Check that a date will occur. '''

	def validate_value(self, value):
		if type(value) not in (datetime.datetime, datetime.date):
			raise ValidationError('The value "%s" is a not valid date object.' % str(value))

		if type(value) is datetime.date:
			value = datetime.datetime.combine(value, datetime.time.min)

		delta = value - datetime.datetime.now()

		if delta.total_seconds() < 0:
			raise ValidationError('"%s" has already happened!' % str(value))

		return True

class IsPast(Konvalidator):
	''' Check that a date has occured. '''

	def validate_value(self, value):
		if type(value) not in (datetime.datetime, datetime.date):
			raise ValidationError('The value "%s" is a not valid date object.' % str(value))

		if type(value) is datetime.date:
			value = datetime.datetime.combine(value, datetime.time.min)

		delta = value - datetime.datetime.now()

		if delta.total_seconds() > 0:
			raise ValidationError('"%s" has not happened yet!' % str(value))

		return True