arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.64k stars 667 forks source link

force exact match on .get() #1084

Open jhonnattan123 opened 2 years ago

jhonnattan123 commented 2 years ago

Issue Description

when executing the following statement:

import arrow
arrow.get('95-03-10 23:01:44','YY-M-D HH:mm:ss')
<Arrow [1995-03-10T23:01:44+00:00]>

the library returns me the date, but I gave it a single M, so it shouldn't have done the .get() but it did. one would expect it to fail, as the correct format should be 'YY-MM-D HH:mm:ss' for that same example.

I would like to know if this is a bug or is there a parameter to force the match to be exact?

System Info

systemcatch commented 2 years ago

Hi @jhonnattan123 this is a bug with the M and MM tokens, we will look into fixing it.

ALee008 commented 2 years ago

Hey there,

I have checked the supported tokens in the documentation. The token M seems to be valid, so

>>> arrow.get('95-03-10 23:01:44','YY-M-D HH:mm:ss')

should not fail, but instead return (no leading zero in front of month):

<Arrow [1995-3-10T23:01:44+00:00]>

Is this conclusion correct?

systemcatch commented 2 years ago

Hey @ALee008 not quite.

I think you are confusing formatting where this M would be valid. Arrow objects always store the month in zero padded form internally.