How to use the datetime.datetime.combine function in DateTime

To help you get started, we’ve selected a few DateTime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HaroldMills / Vesper / vesper / schedule / schedule_parser.py View on Github external
parts = s.split(maxsplit=1)
    
    if len(parts) != 2:
        return None
    
    date = _parse_date(parts[0])
    if date is None:
        return None
    
    time = _parse_time(parts[1])
    if time is None:
        return None
    
    if isinstance(time, datetime.time):
        return datetime.datetime.combine(date, time)
    else:
        return _EventRelativeDateTime(date, time.event_name, time.offset)
github frappe / frappe / frappe / data_migration / doctype / data_migration_connector / connectors / calendar_connector.py View on Github external
day.append("TH")
			if e.friday == 1:
				day.append("FR")
			if e.saturday == 1:
				day.append("SA")
			if e.sunday == 1:
				day.append("SU")

			day = "BYDAY=" + ",".join(str(d) for d in day)
			frequency = "FREQ=WEEKLY"

		elif e.repeat_on == "Every Week":
			frequency = "FREQ=WEEKLY"
		elif e.repeat_on == "Every Month":
			frequency = "FREQ=MONTHLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=-1"
			end_date = datetime.combine(add_days(e.repeat_till, 1), datetime.min.time()).strftime('UNTIL=%Y%m%dT%H%M%SZ')
		elif e.repeat_on == "Every Year":
			frequency = "FREQ=YEARLY"
		else:
			return None

		wst = "WKST=SU"

		elements = [frequency, end_date, wst, day]

		return ";".join(str(e) for e in elements if e is not None and not not e)
github unt-libraries / catalog-api / django / sierra / base / benchmarks.py View on Github external
def _get_test_filter_params(date_from, date_to):
    date_from = datetime.combine(date_from, time(0, 0))
    date_to = datetime.combine(date_to, time(23, 59, 59, 99))
    filter = {
        'record_metadata__record_last_updated_gmt__gte': date_from,
        'record_metadata__record_last_updated_gmt__lte': date_to,
    }
    order_by = ['record_metadata__record_last_updated_gmt']
    prefetch_related = [
        'record_metadata__varfield_set',
        'checkout',
        'bibrecorditemrecordlink_set',
        'bibrecorditemrecordlink_set__bib_record__record_metadata',
        'bibrecorditemrecordlink_set__bib_record__record_metadata'
            + '__varfield_set',
    ]
    select_related = ['record_metadata', 'location', 'itype']
    return [
github the-mace / evtools / solarcity.py View on Github external
daylight_hours = 0
    cloud_cover = 0

    production = float(soup.find(id='ctl00_cphMain_lbProdTotalByChart').text)

    if not day and production == 0 and cloud_cover == 0 and daylight_hours == 0:
        raise Exception("Problem getting current production level: %.1f, %d, %.1f" % (production,
                                                                                      cloud_cover, daylight_hours))

    if daylight_hours == 0:
        """
        SolarCity has had outages where they cant provide the cloud cover/weather information.
        If the weather data appears empty here, we'll go get it from another source
        """
        if day:
            ts = datetime.datetime.combine(day, datetime.datetime.max.time()).strftime("%s")
        else:
            ts = time.time()
        w = get_daytime_weather_data(log, ts)
        cloud_cover = w["cloud_cover"]
        daylight_hours = w["daylight"]

    return daylight_hours, cloud_cover, production
github unitedstack / gringotts / gringotts / checker / service.py View on Github external
def _absolute_9_clock(self):
        nowutc = datetime.datetime.utcnow()
        nowutc_time = nowutc.time()
        nowutc_date = nowutc.date()
        clock = datetime.time(1, 0, 0)
        if nowutc_time > clock:
            nowutc_date = nowutc_date + datetime.timedelta(hours=24)
        return datetime.datetime.combine(nowutc_date, clock)
github pat1 / autoradio / autoradio / gest_playlist.py View on Github external
playlist.ar_url=playlist.playlist.file.url

            #print self.timesched_min, self.timesched_max

            if (self.timesched_min < self.timesched_max):

                #print self.datesched_min.date()
                #print playlist.time

                playlist.ar_scheduledatetime=datetime.datetime.combine(self.datesched_min.date(), playlist.time)
                
            else:
                # we are around midnight we have to check the correct date (today, tomorrow)

                if playlist.time > datetime.time(12):
                    playlist.ar_scheduledatetime=datetime.datetime.combine(self.datesched_min.date(), playlist.time)
                else:
                    playlist.ar_scheduledatetime=datetime.datetime.combine(self.datesched_max.date(), playlist.time)

            playlist.ar_emission_done=playlist.emission_done

#            # calcolo la lunghezza del programma
#            relpath= os.path.basename(playlist.ar_filename)
#            basedir=os.path.dirname(playlist.ar_filename)

#	    try:
#            	meta = metadata.metadata_from_file(relpath, \
#                   basedir, tracknrandtitlere, postprocessors)
#            	playlist.ar_length=meta.length
#	    except:
#            	playlist.ar_length=3600
github schlosser / eventum / app / models / Event.py View on Github external
def start_datetime(self):
        """A convenience method to combine ``start_date`` and ``start_time``
        into one :class:`datetime`.

        :returns: The combined datetime, or ``None` if ``start_date`` or
            ``start_time`` are ``None``.
        :rtype: :class:`datetime`.
        """
        # Check times against None, because midnight is represented by 0.
        if self.start_date is None or self.start_time is None:
            return None
        return datetime.combine(self.start_date, self.start_time)
github learning-unlimited / ESP-Website / esp / useful_scripts / kick_students.py View on Github external
from esp.program.models import Program, StudentRegistration, ClassSection
from esp.users.models import ESPUser
from esp.users.models.userbits import UserBit
from esp.datatree.models import GetNode
from datetime import datetime, timedelta, date, time
from django.db.models.aggregates import Min

# Spark 2013
prog = Program.objects.get(id=88)
# classes that started more than 120 minutes ago
passed_sections = prog.sections().annotate(begin_time=Min("meeting_times__start")).filter(status=10, parent_class__status=10, begin_time__start__lt=datetime.now() - timedelta(minutes=120), begin_time__start__gt = datetime.combine(date.today(), time(0, 0)))
# students who are enrolled in a class that started more than 120 minutes ago, who have not checked in
#students = ESPUser.objects.filter(studentregistration__in=StudentRegistration.valid_objects(), studentregistration__relationship=1, studentregistration__section__in=passed_sections).distinct().exclude(userbit__in=UserBit.valid_objects(), userbit__qsc=prog.anchor, userbit__verb=GetNode('V/Flags/Registration/Attended'))
all_students = ESPUser.objects.filter(studentregistration__in=StudentRegistration.valid_objects(), studentregistration__relationship=1, studentregistration__section__in=passed_sections).distinct()
students = set(all_students) - set(all_students.filter(userbit__in=UserBit.valid_objects(), userbit__qsc=prog.anchor, userbit__verb=GetNode('V/Flags/Registration/Attended')))
# classes that start today
upcoming_sections = prog.sections().annotate(begin_time=Min("meeting_times__start")).filter(status=10, parent_class__status=10, begin_time__start__gt=datetime.now(), begin_time__start__lt=datetime.combine(date.today(), time(23, 59)))
# registrations of missing students for upcoming classes
registrations = StudentRegistration.valid_objects().filter(user__in=students, section__in=upcoming_sections, relationship=1)
# filter out materials-intensive classes
registrations = registrations.exclude(section__parent_class__id__in=[6866,6914,6926,6927,6932,6943,6948,6958,6970,6971,6993,7006,7009,7021,7191,7187,7186,7026,7030,7180,7178,7047,7168,7050,7051,7056,7059,7164,7060,7161,7063,7156,7151,7150,7146,7144,7141,7064,7077,7137,7082,7135,7127,7123,7117,7104,7102,7098,7097,7089,7088,7087,7083])
registrations.update(end_date=datetime.now())
print list(registrations)
github briancappello / py-yaml-fixtures / py_yaml_fixtures / utils.py View on Github external
def datetime_factory(value):
    if value in {None, '', 'None'}:
        return None
    elif isinstance(value, datetime):
        return value
    elif isinstance(value, date):
        return datetime.combine(value, time(tzinfo=timezone.utc))
    elif value in {'today', 'now', 'utcnow'}:
        return datetime.now(timezone.utc)
    return parse_datetime(value)