Turn a date into a datetime at midnight.
541258
def to_datetime(date):
    
    return datetime.datetime.combine(date, datetime.datetime.min.time())
351862
def merge_datetime(date, time='', date_format='%d/%m/%Y', time_format='%H:%M'):
    """"""
    day = datetime.strptime(date, date_format)
    if time:
        time = datetime.strptime(time, time_format)
        time = datetime.time(time)
        day = datetime.date(day)
        day = datetime.combine(day, time)
    return day
1241723
def last_midnight():
    
    now = datetime.now()
    return datetime(now.year, now.month, now.day)
1289058
function setDate(node, date, binary) {
    if (date) {
        if (binary) {
            var secondsFrom00 = Math.floor(date.getTime() / 1000) + EpochSeconds;
            var bytes = new DataView(new ArrayBuffer(8));
            var val64 = Int64.from(secondsFrom00);
            bytes.setUint32(0, val64.lo, true);
            bytes.setUint32(4, val64.hi, true);
            setText(node, ByteUtils.bytesToBase64(bytes.buffer));
        } else {
            setText(node, date.toISOString().replace(dateRegex, ''));
        }
    } else {
        setText(node, '');
    }
}
1061130
def sqlalch_datetime(dt):
    """"""
    if isinstance(dt, str):
        return datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=UTC)
    if dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None:
        return dt.astimezone(UTC)
    return dt.replace(tzinfo=UTC)
985452
def midnight(arg=None):
    
    if arg:
        _arg = parse(arg)
        if isinstance(_arg, datetime.date):
            return datetime.datetime.combine(_arg, datetime.datetime.min.time())
        elif isinstance(_arg, datetime.datetime):
            return datetime.datetime.combine(_arg.date(), datetime.datetime.min.time())
    else:
        return datetime.datetime.combine(_date, datetime.datetime.min.time())
162453
private Date adjustDate(final Date date) {
        
        if(!isDateStart1904() && date.getTime() < ExcelDateUtils.MILLISECONDS_19000101) {
            return new Date(date.getTime() + TimeUnit.DAYS.toMillis(1));
        }
        
        return date;
    }
1203908
def date_cast(date):
    '''
    
    '''
    if date is None:
        return datetime.datetime.now()
    elif isinstance(date, datetime.datetime):
        return date

    # fuzzy date
    try:
        if isinstance(date, six.string_types):
            try:
                if HAS_TIMELIB:
                    # py3: yes, timelib.strtodatetime wants bytes, not str :/
                    return timelib.strtodatetime(
                        salt.utils.stringutils.to_bytes(date))
            except ValueError:
                pass

            # not parsed yet, obviously a timestamp?
            if date.isdigit():
                date = int(date)
            else:
                date = float(date)

        return datetime.datetime.fromtimestamp(date)
    except Exception:
        if HAS_TIMELIB:
            raise ValueError('Unable to parse {0}'.format(date))

        raise RuntimeError(
                'Unable to parse {0}. Consider installing timelib'.format(date))
640424
def naturaldate(date, include_seconds=False):
    """"""

    if not date:
        return ''

    right_now = now()
    today = datetime(right_now.year, right_now.month,
                     right_now.day, tzinfo=right_now.tzinfo)
    delta = right_now - date
    delta_midnight = today - date

    days = delta.days
    hours = delta.seconds // 3600
    minutes = delta.seconds // 60
    seconds = delta.seconds

    if days < 0:
        return _('just now')

    if days == 0:
        if hours == 0:
            if minutes > 0:
                return ungettext(
                    _('{minutes} minute ago'),
                    _('{minutes} minutes ago'), minutes
                ).format(minutes=minutes)
            else:
                if include_seconds and seconds:
                    return ungettext(
                        _('{seconds} second ago'),
                        _('{seconds} seconds ago'), seconds
                    ).format(seconds=seconds)
                return _('just now')
        else:
            return ungettext(
                _('{hours} hour ago'), _('{hours} hours ago'), hours
            ).format(hours=hours)

    if delta_midnight.days == 0:
        return _('yesterday at {time}').format(time=date.strftime('%H:%M'))

    count = 0
    for chunk, pluralizefun in OLDER_CHUNKS:
        if days >= chunk:
            count = int(round((delta_midnight.days + 1) / chunk, 0))
            fmt = pluralizefun(count)
            return fmt.format(num=count)
493297
def datetime_to_time(date, time):
    """"""
    if (255 in date) or (255 in time):
        raise RuntimeError("specific date and time required")

    time_tuple = (
        date[0]+1900, date[1], date[2],
        time[0], time[1], time[2],
        0, 0, -1,
        )
    return _mktime(time_tuple)
555532
def datetime_to_timestamp(dt):
    """"""
    delta = dt - datetime.utcfromtimestamp(0)
    return delta.seconds + delta.days * 24 * 3600
1199745
def prepare_date(data, schema):
    """"""
    if isinstance(data, datetime.date):
        return data.toordinal() - DAYS_SHIFT
    else:
        return data
530110
def date_elem(ind_days, ind_minutes):
    """"""
    def inner(seq):
        return nexrad_to_datetime(seq[ind_days], seq[ind_minutes] * 60 * 1000)
    return inner
454122
def Date(value):
    """"""
    from datetime import datetime
    try:
        return datetime(*reversed([int(val) for val in value.split('/')]))
    except Exception as err:
        raise argparse.ArgumentTypeError("invalid date '%s'" % value)
899978
def normalize(self, dt, is_dst=False):
        """"""
        if dt.tzinfo is self:
            return dt
        if dt.tzinfo is None:
            raise ValueError('Naive time - no tzinfo set')
        return dt.astimezone(self)
131800
def _decode_datetime(obj):
    """"""

    if '__datetime__' in obj:
        obj = datetime.datetime.strptime(obj['as_str'].decode(), "%Y%m%dT%H:%M:%S.%f")
    return obj
586719
def date_to_um_date(date):
    

    assert date.hour == 0 and date.minute == 0 and date.second == 0

    return [date.year, date.month, date.day, 0, 0, 0]