How to use the datetime.date.fromtimestamp 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 benfred / github-analysis / scripts / plot.py View on Github external
def load_data(basedir):
    now = datetime.date.fromtimestamp(time.time() - 86400)
    languages = defaultdict(list)
    mau = {}
    for year in range(2011, now.year + 1):
        for month in range(1, now.month if year == now.year else 13):
            mau_file = os.path.join(basedir, "%04i" % year, "%02i" % month, MAU_FILENAME)
            try:
                total_mau = int(open(mau_file).read().split()[0])
            except Exception as e:
                log.info("Skipping %s: %s", mau_file, e)
                continue

            if total_mau <= 1000:
                log.info("Skipping %s: insufficient mau of %i", mau_file, total_mau)
                continue

            date = datetime.datetime(year, month, 28)
github ComputerScienceHouse / conditional / conditional / models / models.py View on Github external
def __init__(self, name, onfloor, room=None, missed=None):
        self.name = name
        today = date.fromtimestamp(time.time())
        self.eval_date = today + timedelta(weeks=10)
        self.onfloor_status = onfloor
        self.room_number = room
        self.signatures_missed = missed
github machinalis / eff / eff_site / eff / templatetags / workedhours.py View on Github external
def aux_mk_time(date_string):
    _date = time.mktime(time.strptime(date_string, '%Y-%m-%d'))
    _date = date.fromtimestamp(_date)
    return _date
github pilat / redis-astra / astra / validators.py View on Github external
def _convert_get(self, value):
        try:
            value = int(value or 0)
        except ValueError:
            return None
        # TODO: maybe use utcfromtimestamp?.
        return dt.date.fromtimestamp(value)
github sqlobject / sqlobject / sqlobject / util / csvimport.py View on Github external
def parse_date(v):
    v = v.strip()
    if not v:
        return None
    if v.startswith('NOW-') or v.startswith('NOW+'):
        days = int(v[3:])
        now = date.today()
        return now + timedelta(days)
    else:
        parsed = time.strptime(v, '%Y-%m-%d')
        return date.fromtimestamp(time.mktime(parsed))
github kynikos / outspline / src / outspline / extensions / organism_basicrules / occur_monthly_weekday_direct.py View on Github external
month = months[0]
        year = date.year + 1
    else:
        year = date.year

    while True:
        first_month_weekday = calendar.monthrange(year, month)[0]
        selected_day_number = (weekday - first_month_weekday + 7) % 7 + 1 + \
                                                                     number * 7

        try:
            sdate = _datetime.datetime(year, month, selected_day_number,
                                                                startH, startM)
        except ValueError:
            # Prevent infinite loops
            maxdate = _datetime.date.fromtimestamp(maxt)
            testdate = _datetime.date(year, month, 1)

            if maxdate < testdate:
                break
        else:
            start = int(_time.mktime(sdate.timetuple()))

            try:
                end = start + rend
            except TypeError:
                end = None

            try:
                alarm = start - ralarm
            except TypeError:
                alarm = None
github ColumbiaDVMM / ColumbiaImageSearch / workflows / get-images-domain / get-images-domain.py View on Github external
ingestion_id = None

    # Get es_ts_start and es_ts_end
    if c_options.es_ts_start is not None:
        es_ts_start = c_options.es_ts_start
    if c_options.es_ts_end is not None:
        es_ts_end = c_options.es_ts_end
    if c_options.es_ts_start is None and c_options.es_ts_end is None and c_options.day_to_process is not None:
        # Compute for day to process
        import calendar
        import dateutil.parser
        try:
            start_date = dateutil.parser.parse(c_options.day_to_process)
            es_ts_end = calendar.timegm(start_date.utctimetuple())*1000
            es_ts_start = es_ts_end - day_gap
            ingestion_id = datetime.date.fromtimestamp((es_ts_start) / 1000).isoformat()
        except Exception as inst:
            print "[get_ingestion_start_end_id: log] Could not parse 'day_to_process'. Getting everything form the CDR."

    # Otherwise consider we want ALL images
    if es_ts_start is None:
        es_ts_start = 0
    if es_ts_end is None:
        es_ts_end = max_ts

    # Form ingestion id if not set yet
    if ingestion_id is None:
        ingestion_id = '-'.join([c_options.es_domain, str(es_ts_start), str(es_ts_end)])

    return es_ts_start, es_ts_end, ingestion_id
github josteink / autoarchiver / archive.py View on Github external
def get_date_modified(filename):
    t = os.path.getmtime(filename)
    return datetime.date.fromtimestamp(t)
github stoq / stoq / stoqlib / net / calendarevents.py View on Github external
def render_GET(self, resource):
        start = datetime.date.fromtimestamp(float(resource.args['start'][0]))
        end = datetime.date.fromtimestamp(float(resource.args['end'][0]))

        store = api.new_store()
        day_events = {}
        if resource.args.get('in_payments', [''])[0] == 'true':
            self._collect_inpayments(start, end, day_events, store)
        if resource.args.get('out_payments', [''])[0] == 'true':
            self._collect_outpayments(start, end, day_events, store)
        if resource.args.get('purchase_orders', [''])[0] == 'true':
            self._collect_purchase_orders(start, end, day_events, store)
        if resource.args.get('client_calls', [''])[0] == 'true':
            self._collect_client_calls(start, end, day_events, store)
        if resource.args.get('client_birthdays', [''])[0] == 'true':
            self._collect_client_birthdays(start, end, day_events, store)
        if resource.args.get('work_orders', [''])[0] == 'true':
            self._collect_work_orders(start, end, day_events, store)
github EOX-A / ngeo-b / ngeo_browse_server / control / control / logview.py View on Github external
def date_of_file(filename):
    return date.fromtimestamp(getmtime(filename))