pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

FAQ example for parse fails in version 2

Open richieadler opened this issue 6 years ago • 1 comments

PythonWin 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32.

>>> import pendulum
>>> pendulum.parse('2016-1-17')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python36-32\lib\site-packages\pendulum\parser.py", line 20, in parse
    return _parse(text, **options)
  File "C:\Python36-32\lib\site-packages\pendulum\parser.py", line 36, in _parse
    parsed = base_parse(text, **options)
  File "C:\Python36-32\lib\site-packages\pendulum\parsing\__init__.py", line 64, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "C:\Python36-32\lib\site-packages\pendulum\parsing\__init__.py", line 116, in _parse
    raise ParserError('Unable to parse string [{}]'.format(text))
pendulum.parsing.exceptions.ParserError: Unable to parse string [2016-1-17]
>>> pendulum.parse('2016-01-17')
DateTime(2016, 1, 17, 0, 0, 0, tzinfo=Timezone('UTC'))
>>> pendulum.__version__
'2.0.2'

richieadler avatar May 31 '18 14:05 richieadler

I can confirm this.

FAQ needs to be updated.

Due to the Parsing documentation, Pendulum can try to parse uncommon date strings using dateutil parser with strict=False argument.

Or the second option is to change pendulum.parse('2016-1-17') example to pendulum.parse('2016-01-17') (notice that month has leading zero now).

But probably it needs more work to be done to make it really useful.

senpos avatar Jun 07 '18 13:06 senpos