Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contructor issue with non-None timezone #658

Closed
mafycek opened this issue Sep 9, 2019 · 5 comments · Fixed by #664
Closed

Contructor issue with non-None timezone #658

mafycek opened this issue Sep 9, 2019 · 5 comments · Fixed by #664
Labels

Comments

@mafycek
Copy link

mafycek commented Sep 9, 2019

Constructor of Arrow object (arrow.py) fails if tzinfo is non-None and if it does not contain field "zone".

The problematic part:

            isinstance(tzinfo, dt_tzinfo)
            and hasattr(tzinfo, "localize")
            and tzinfo.zone
        ):

should be like

            isinstance(tzinfo, dt_tzinfo)
            and hasattr(tzinfo, "localize")
            and hasattr(tzinfo, "zone")
        ):

The change came since version 0.14.5

@systemcatch
Copy link
Collaborator

Hello @mafycek, I don't understand what you mean, please can you provide a reproducible example.

@jadchaar
Copy link
Member

jadchaar commented Sep 9, 2019

Hey thanks for reporting this. Like Chris said, it would be great to have an example input that causes Arrow to fail so we can write a regression test :).

@mafycek
Copy link
Author

mafycek commented Sep 9, 2019

Hi guys,
hope that you are well.
Say, I have a (simple) program like:

import arrow
import dateparser

date_that_succeds = "1990-01-01T00:00:00"
date_that_fails = "1990-01-01T00:00:00+00:00"

for date in [date_that_succeds, date_that_fails]:
    try:
        parsed_date = dateparser.parse(date, date_formats=None or ['%d %B %Y', '%d/%m/%y', '%d/%m/%Y', '%d.%m.%Y'])
        arrow_date = arrow.get(parsed_date)
        print(date_that_succeded, arrow_date)
    except:
        print("It failed on date " + date)

Results:
with arrow 0.15.0 (since 0.14.5)
The first date passes however the the second fails.
with arrow 0.14.4 (I tested on 0.13.1)
Both pass

Explanation of the failure:
parsed_date is of type datetime with component variable tzinfo of type StaticTzInfo. The StaticTzInfo type has two component variables _StaticTzInfo__name of type str and _StaticTzInfo__offset of type timedelta. When such variable is inserted into arrow through get it fails in the constructor of arrow class because tzinfo in the constructor is of type StaticTzInfo that does not have component variable zone and that is why the interpreter says
AttributeError: 'StaticTzInfo' object has no attribute 'zone'

My comment:
I do not know if the test of zone component is correct. If yes that it should test presence of the variable and then the value if that is needed.

Regression for this case would be really needed. Well, it could test more that one timezone and take into account some special ones with non-integer shifts.

Bye,
Hynek

@jadchaar jadchaar added the bug label Sep 10, 2019
@mafycek
Copy link
Author

mafycek commented Sep 10, 2019

Colleague of mine fixed unnecessary stuff and typo. However the message is the same:

import arrow
import dateparser

date_that_succeeds = "1990-01-01T00:00:00"
date_that_fails = "1990-01-01T00:00:00+00:00"

for date in [date_that_succeeds, date_that_fails]:
    try:
        parsed_date = dateparser.parse(date, date_formats=['%d %B %Y', '%d/%m/%y', '%d/%m/%Y', '%d.%m.%Y'])
        arrow_date = arrow.get(parsed_date)
        print(date, arrow_date)
    except:
        print("It failed on date " + date)

@systemcatch
Copy link
Collaborator

systemcatch commented Sep 10, 2019

Thanks @mafycek, we will do some digging on this bug and look at fixes.

Useful note, you can wrap python code blocks like this.

```python
INSERT BUG HERE
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants