本文整理汇总了Python中dateutil.parser.parserinfo方法的典型用法代码示例。如果您正苦于以下问题:Python parser.parserinfo方法的具体用法?Python parser.parserinfo怎么用?Python parser.parserinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dateutil.parser
的用法示例。
在下文中一共展示了parser.parserinfo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_parsed_assessment_due_date
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def get_parsed_assessment_due_date(assessment_item):
"""
Returns the parsed due date for the given assessment item as a datetime
object. If the date cannot be parsed, a DateSyntaxException is raised.
"""
course_name, _, due_date, _ = assessment_item
if due_date == 'Examination Period':
return get_current_exam_period()
parser_info = parser.parserinfo(dayfirst=True)
try:
# If a date range is detected, attempt to split into start and end
# dates. Else, attempt to just parse the whole thing.
if ' - ' in due_date:
start_date, end_date = due_date.split(' - ', 1)
start_datetime = parser.parse(start_date, parser_info)
end_datetime = parser.parse(end_date, parser_info)
return start_datetime, end_datetime
due_datetime = parser.parse(due_date, parser_info)
return due_datetime, due_datetime
except Exception:
raise DateSyntaxException(due_date, course_name)
示例2: test_convertyear
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def test_convertyear(n):
assert n == parserinfo().convertyear(n)
示例3: test_convertyear_no_specified_century
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def test_convertyear_no_specified_century(n):
p = parserinfo()
new_year = p._year + n
result = p.convertyear(new_year % 100, century_specified=False)
assert result == new_year
示例4: testParserAll
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def testParserAll(self):
# All interface
from dateutil.parser import parse
from dateutil.parser import parserinfo
# Other public classes
from dateutil.parser import parser
for var in (parse, parserinfo, parser):
self.assertIsNot(var, None)
示例5: _get_date_parser
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def _get_date_parser():
from dateutil.parser import parser, parserinfo
info = parserinfo()
info._year = 1930 + 50
info._century = 1900
return parser(info)
示例6: parse_approximate_date
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def parse_approximate_date(s):
"""Take any reasonable date string, and return an ApproximateDate for it
>>> ad = parse_approximate_date('2014-02-17')
>>> type(ad)
<class 'django_date_extensions.fields.ApproximateDate'>
>>> ad
2014-02-17
>>> parse_approximate_date('2014-02')
2014-02-00
>>> parse_approximate_date('2014')
2014-00-00
>>> parse_approximate_date('future')
future
"""
user_settings = get_current_usersettings()
for regexp in [
r'^(\d{4})-(\d{2})-(\d{2})$',
r'^(\d{4})-(\d{2})$',
r'^(\d{4})$'
]:
m = re.search(regexp, s)
if m:
return ApproximateDate(*(int(g, 10) for g in m.groups()))
if s == 'future':
return ApproximateDate(future=True)
if s:
dt = parser.parse(
s,
parserinfo=localparserinfo(),
dayfirst=user_settings.DD_MM_DATE_FORMAT_PREFERRED
)
return ApproximateDate(dt.year, dt.month, dt.day)
raise ValueError("Couldn't parse '{0}' as an ApproximateDate".format(s))
示例7: parse_seminar_date
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def parse_seminar_date(date_string: str, url: str) -> datetime:
"""
Parses a date string as Brisbane Time.
"""
parser_info = parser.parserinfo(dayfirst=True)
try:
# The dates and times on the seminars page don't specify a timezone, so
# the datetime returned by the parser will always be a native datetime
date = parser.parse(date_string, parser_info)
# Therefore, we must set the Brisbane Time Zone information.
return date.replace(tzinfo=BRISBANE_TZ)
except Exception:
raise InvalidFormatException(url, f'Could not parse the date {date_string}')
示例8: to_parserinfo
# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import parserinfo [as 别名]
def to_parserinfo(self, base_cls=parser.parserinfo):
attributes = {
'JUMP': self.info.get('skip', []),
'PERTAIN': self.info.get('pertain', []),
'WEEKDAYS': [self.info['monday'],
self.info['tuesday'],
self.info['wednesday'],
self.info['thursday'],
self.info['friday'],
self.info['saturday'],
self.info['sunday']],
'MONTHS': [self.info['january'],
self.info['february'],
self.info['march'],
self.info['april'],
self.info['may'],
self.info['june'],
self.info['july'],
self.info['august'],
self.info['september'],
self.info['october'],
self.info['november'],
self.info['december']],
'HMS': [self.info['hour'],
self.info['minute'],
self.info['second']],
}
name = '{language}ParserInfo'.format(language=self.info['name'])
return type(name, bases=[base_cls], dict=attributes)