当前位置: 首页>>代码示例>>Python>>正文


Python arrow.parser方法代码示例

本文整理汇总了Python中arrow.parser方法的典型用法代码示例。如果您正苦于以下问题:Python arrow.parser方法的具体用法?Python arrow.parser怎么用?Python arrow.parser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arrow的用法示例。


在下文中一共展示了arrow.parser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grok_datetime

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import parser [as 别名]
def grok_datetime(dstring):
    more_formats = ['YYYYMMDDTHHmmss', 'YYYYMMDDTHHmmssZ', 'YYYYMMDD']
    parser = DateTimeParser()
    parser.SEPARATORS += ['']

    # Try to parse datetime string in regular ISO 8601 format
    try:
        return parser.parse_iso(dstring)

    # Fall back to parse datetime string in additional convenience formats
    except arrow.parser.ParserError as ex:
        for format in more_formats:
            try:
                return parser.parse(dstring, format)
            except arrow.parser.ParserError as ex:
                pass

    # Fall back to attempt to parse as relative datetime expression, e.g. "now-10m"
    return get_timedelta(dstring) 
开发者ID:daq-tools,项目名称:kotori,代码行数:21,代码来源:influx.py

示例2: iso8601_to_dt

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import parser [as 别名]
def iso8601_to_dt(iso8601):
    """Given an ISO8601 string as returned by Device Cloud, convert to a datetime object"""
    # We could just use arrow.get() but that is more permissive than we actually want.
    # Internal (but still public) to arrow is the actual parser where we can be
    # a bit more specific
    parser = DateTimeParser()
    try:
        arrow_dt = arrow.Arrow.fromdatetime(parser.parse_iso(iso8601))
        return arrow_dt.to('utc').datetime
    except ParserError as pe:
        raise ValueError("Provided was not a valid ISO8601 string: %r" % pe) 
开发者ID:digidotcom,项目名称:python-devicecloud,代码行数:13,代码来源:util.py

示例3: strict_parse_args

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import parser [as 别名]
def strict_parse_args(parser, raw_args):
    """
    Wrapper around parser.parse_args that raises a ValueError if unexpected
    arguments are present.

    """
    args = parser.parse_args()
    unexpected_params = (set(raw_args) - {allowed_arg.name for allowed_arg in
                                          parser.args})
    if unexpected_params:
        raise InputError('Unexpected query parameters {}'.format(
                         unexpected_params))
    return args 
开发者ID:nylas,项目名称:sync-engine,代码行数:15,代码来源:validation.py


注:本文中的arrow.parser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。