當前位置: 首頁>>代碼示例>>Python>>正文


Python date.fromordinal方法代碼示例

本文整理匯總了Python中datetime.date.fromordinal方法的典型用法代碼示例。如果您正苦於以下問題:Python date.fromordinal方法的具體用法?Python date.fromordinal怎麽用?Python date.fromordinal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datetime.date的用法示例。


在下文中一共展示了date.fromordinal方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _unconvert_index

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def _unconvert_index(data, kind, encoding=None):
    kind = _ensure_decoded(kind)
    if kind == u('datetime64'):
        index = DatetimeIndex(data)
    elif kind == u('datetime'):
        index = np.array([datetime.fromtimestamp(v) for v in data],
                         dtype=object)
    elif kind == u('date'):
        try:
            index = np.array(
                [date.fromordinal(v) for v in data], dtype=object)
        except (ValueError):
            index = np.array(
                [date.fromtimestamp(v) for v in data], dtype=object)
    elif kind in (u('integer'), u('float')):
        index = np.array(data)
    elif kind in (u('string')):
        index = _unconvert_string_array(data, nan_rep=None, encoding=encoding)
    elif kind == u('object'):
        index = np.array(data[0])
    else:  # pragma: no cover
        raise ValueError('unrecognized index type %s' % kind)
    return index 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:pytables.py

示例2: _unconvert_index

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def _unconvert_index(data, kind, encoding=None):
    kind = _ensure_decoded(kind)
    if kind == u('datetime64'):
        index = DatetimeIndex(data)
    elif kind == u('timedelta64'):
        index = TimedeltaIndex(data)
    elif kind == u('datetime'):
        index = np.asarray([datetime.fromtimestamp(v) for v in data],
                           dtype=object)
    elif kind == u('date'):
        try:
            index = np.asarray(
                [date.fromordinal(v) for v in data], dtype=object)
        except (ValueError):
            index = np.asarray(
                [date.fromtimestamp(v) for v in data], dtype=object)
    elif kind in (u('integer'), u('float')):
        index = np.asarray(data)
    elif kind in (u('string')):
        index = _unconvert_string_array(data, nan_rep=None, encoding=encoding)
    elif kind == u('object'):
        index = np.asarray(data[0])
    else:  # pragma: no cover
        raise ValueError('unrecognized index type %s' % kind)
    return index 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:27,代碼來源:pytables.py

示例3: _unconvert_index

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def _unconvert_index(data, kind, encoding=None, errors='strict'):
    kind = _ensure_decoded(kind)
    if kind == u'datetime64':
        index = DatetimeIndex(data)
    elif kind == u'timedelta64':
        index = TimedeltaIndex(data)
    elif kind == u'datetime':
        index = np.asarray([datetime.fromtimestamp(v) for v in data],
                           dtype=object)
    elif kind == u'date':
        try:
            index = np.asarray(
                [date.fromordinal(v) for v in data], dtype=object)
        except (ValueError):
            index = np.asarray(
                [date.fromtimestamp(v) for v in data], dtype=object)
    elif kind in (u'integer', u'float'):
        index = np.asarray(data)
    elif kind in (u'string'):
        index = _unconvert_string_array(data, nan_rep=None, encoding=encoding,
                                        errors=errors)
    elif kind == u'object':
        index = np.asarray(data[0])
    else:  # pragma: no cover
        raise ValueError('unrecognized index type {kind}'.format(kind=kind))
    return index 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:pytables.py

示例4: _unconvert_index

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def _unconvert_index(data, kind, encoding=None, errors='strict'):
    kind = _ensure_decoded(kind)
    if kind == u('datetime64'):
        index = DatetimeIndex(data)
    elif kind == u('timedelta64'):
        index = TimedeltaIndex(data)
    elif kind == u('datetime'):
        index = np.asarray([datetime.fromtimestamp(v) for v in data],
                           dtype=object)
    elif kind == u('date'):
        try:
            index = np.asarray(
                [date.fromordinal(v) for v in data], dtype=object)
        except (ValueError):
            index = np.asarray(
                [date.fromtimestamp(v) for v in data], dtype=object)
    elif kind in (u('integer'), u('float')):
        index = np.asarray(data)
    elif kind in (u('string')):
        index = _unconvert_string_array(data, nan_rep=None, encoding=encoding,
                                        errors=errors)
    elif kind == u('object'):
        index = np.asarray(data[0])
    else:  # pragma: no cover
        raise ValueError('unrecognized index type %s' % kind)
    return index 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:28,代碼來源:pytables.py

示例5: fromordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def fromordinal(ordinal):
        """Return the date corresponding to the proleptic Gregorian ordinal.

         January 1 of year 1 has ordinal 1. ValueError is raised unless
         1 <= ordinal <= date.max.toordinal().
         For any date d, date.fromordinal(d.toordinal()) == d.
         """ 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:idatetime.py

示例6: toordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def toordinal():
        """Return the proleptic Gregorian ordinal of the date

        January 1 of year 1 has ordinal 1. For any date object d,
        date.fromordinal(d.toordinal()) == d.
        """ 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:8,代碼來源:idatetime.py

示例7: get_values

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def get_values(self, data, filter_values):
        field = self._params['field']
        min_value = get_value(data, 'min_start'.format(field))
        max_value = get_value(data, 'max_end'.format(field))

        if not (min_value and max_value):
            return None

        return {
            'min': date.fromordinal(int(min_value)),
            'max': date.fromordinal(int(max_value)),
            'days': max_value - min_value,
        } 
開發者ID:opendatateam,項目名稱:udata,代碼行數:15,代碼來源:fields.py

示例8: fromordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def fromordinal(ordinal):
        """Return the date corresponding to the proleptic Gregorian ordinal.

         January 1 of year 1 has ordinal 1. `ValueError` is raised unless
         1 <= ordinal <= date.max.toordinal().

         For any date *d*, ``date.fromordinal(d.toordinal()) == d``.
         """ 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:10,代碼來源:idatetime.py

示例9: toordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def toordinal():
        """Return the proleptic Gregorian ordinal of the date

        January 1 of year 1 has ordinal 1. For any date object *d*,
        ``date.fromordinal(d.toordinal()) == d``.
        """ 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:8,代碼來源:idatetime.py

示例10: test_fromordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def test_fromordinal():
    assert pendulum.Date.fromordinal(730120) == date.fromordinal(730120) 
開發者ID:sdispater,項目名稱:pendulum,代碼行數:4,代碼來源:test_behavior.py

示例11: fromordinal

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def fromordinal(n):
        return DateWithFuture(date=date_class.fromordinal(n)) 
開發者ID:codeforpdx,項目名稱:recordexpungPDX,代碼行數:4,代碼來源:util.py

示例12: _get_json_for_random_dates

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def _get_json_for_random_dates(count, use_concept_tags, thumbs):
    """
    This returns the JSON data for a set of randomly chosen dates. The number of dates is specified by the count
    parameter
    :param count:
    :param use_concept_tags:
    :return:
    """

    if count > 100 or count <= 0:
        raise ValueError('Count must be positive and cannot exceed 100')

    begin_ordinal = datetime(1995, 6, 16).toordinal()
    today_ordinal = datetime.today().toordinal()

    date_range = range(begin_ordinal, today_ordinal + 1)
    random_date_ordinals = sample(date_range, count)

    all_data = []
    for date_ordinal in random_date_ordinals:
        dt = date.fromordinal(date_ordinal)
        data = _apod_handler(dt, use_concept_tags, date_ordinal == today_ordinal, thumbs)
        data['service_version'] = SERVICE_VERSION
        all_data.append(data)

    return jsonify(all_data) 
開發者ID:nasa,項目名稱:apod-api,代碼行數:28,代碼來源:application.py

示例13: random_date

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def random_date(starting_date=None):
    starting_date = starting_date or earliest
    # ordinal dates are easier to pick random between
    start_date = starting_date.toordinal()
    end_date = now.toordinal()
    return date.fromordinal(randint(start_date, end_date)) 
開發者ID:cuttlesoft,項目名稱:flask-bitmapist,代碼行數:8,代碼來源:seed.py

示例14: datespan

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def datespan(fromdate, todate, fromdateincl=True, todateincl=True,
             key='dateid',
             strings={'date': '%Y-%m-%d', 'monthname': '%B', 'weekday': '%A'},
             ints={'year': '%Y', 'month': '%m', 'day': '%d'},
             expander=None):
    """Return a generator yielding dicts for all dates in an interval.

       Arguments:
           
       - fromdate: The lower bound for the date interval. Should be a
         datetime.date or a YYYY-MM-DD formatted string.
       - todate: The upper bound for the date interval. Should be a
         datetime.date or a YYYY-MM-DD formatted string.
       - fromdateincl: Decides if fromdate is included. Default: True
       - todateincl: Decides if todate is included. Default: True
       - key: The name of the attribute where an int (YYYYMMDD) that uniquely
         identifies the date is stored. Default: 'dateid'.
       - strings: A dict mapping attribute names to formatting directives (as
         those used by strftime). The returned dicts will have the specified
         attributes as strings.
         Default: {'date':'%Y-%m-%d', 'monthname':'%B', 'weekday':'%A'}
       - ints: A dict mapping attribute names to formatting directives (as
         those used by strftime). The returned dicts will have the specified
         attributes as ints.
         Default: {'year':'%Y', 'month':'%m', 'day':'%d'}
       - expander: A callable f(date, dict) that is invoked on each created
         dict. Not invoked if None. Default: None
    """

    for arg in (fromdate, todate):
        if not ((type(arg) in _stringtypes and arg.count('-') == 2) or
                isinstance(arg, date)):
            raise ValueError(
                "fromdate and today must be datetime.dates or " +
                "YYYY-MM-DD formatted strings")

    (year, month, day) = fromdate.split('-')
    fromdate = date(int(year), int(month), int(day))

    (year, month, day) = todate.split('-')
    todate = date(int(year), int(month), int(day))

    start = fromdate.toordinal()
    if not fromdateincl:
        start += 1

    end = todate.toordinal()
    if todateincl:
        end += 1

    for i in range(start, end):
        d = date.fromordinal(i)
        res = {}
        res[key] = int(d.strftime('%Y%m%d'))
        for (att, attformat) in strings.iteritems():
            res[att] = d.strftime(attformat)
        for (att, attformat) in ints.iteritems():
            res[att] = int(d.strftime(attformat))
        if expander is not None:
            expander(d, res)
        yield res 
開發者ID:chrthomsen,項目名稱:pygrametl,代碼行數:63,代碼來源:__init__.py

示例15: convert

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import fromordinal [as 別名]
def convert(self, values, nan_rep, encoding):
        """set the data from this selection (and convert to the correct dtype
        if we can)
        """
        try:
            values = values[self.cname]
        except:
            pass
        self.set_data(values)

        # convert to the correct dtype
        if self.dtype is not None:
            dtype = _ensure_decoded(self.dtype)

            # reverse converts
            if dtype == u('datetime64'):
                # recreate the timezone
                if self.tz is not None:

                    # data should be 2-dim here
                    # we stored as utc, so just set the tz

                    index = DatetimeIndex(
                        self.data.ravel(), tz='UTC').tz_convert(self.tz)
                    self.data = np.array(
                        index.tolist(), dtype=object).reshape(self.data.shape)

                else:
                    self.data = np.asarray(self.data, dtype='M8[ns]')

            elif dtype == u('timedelta64'):
                self.data = np.asarray(self.data, dtype='m8[ns]')
            elif dtype == u('date'):
                try:
                    self.data = np.array(
                        [date.fromordinal(v) for v in self.data], dtype=object)
                except ValueError:
                    self.data = np.array(
                        [date.fromtimestamp(v) for v in self.data],
                        dtype=object)
            elif dtype == u('datetime'):
                self.data = np.array(
                    [datetime.fromtimestamp(v) for v in self.data],
                    dtype=object)
            else:

                try:
                    self.data = self.data.astype(dtype)
                except:
                    self.data = self.data.astype('O')

        # convert nans / decode
        if _ensure_decoded(self.kind) == u('string'):
            self.data = _unconvert_string_array(
                self.data, nan_rep=nan_rep, encoding=encoding)

        return self 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:59,代碼來源:pytables.py


注:本文中的datetime.date.fromordinal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。